[android]代码库
//前台ui线程在显示ProgressDialog,
//后台线程在下载数据,数据下载完毕,关闭进度框
@Override
public void onClick (View view) {
switch (view.getId() ) {
case R.id.btnFirst:
dialog = ProgressDialog.show (this, "",
"下载数据,请稍等 …", true, true);
//启动一个后台线程
handler.post (new Runnable() {
@Override
public void run() {
//这里下载数据
try {
URL url = new URL (params);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoInput (true);
conn.connect();
InputStream inputStream = conn.getInputStream();
bitmap = BitmapFactory.decodeStream (inputStream);
Message msg = new Message();
msg.what = 1;
handler.sendMessage (msg);
} catch (MalformedURLException e1) {
e1.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
break;
初级程序员
by: dodo 发表于:2013-06-25 11:33:59 顶(0) | 踩(0) 回复
这个,这个。。
回复评论