Android 连接网络时显示进度条
2010-08-31 00:06:00 来源:WEB开发网public class HelloXML extends Activity {
private static final int MESSAGETYPE_01 = 0x0001;
private ProgressDialog progressDialog = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.main);
progressDialog = ProgressDialog.show(HelloXML.this, "下载", "正在下载,请稍候!");
new Thread() {
public void run() {
try {
// 连接网络获取数据
} catch (Exception e) {
// 在GUI显示错误提示
// tv.setText("Error: " + e.getMessage());
}
Message msg_listData = new Message();
msg_listData.what = MESSAGETYPE_01;
handler.sendMessage(msg_listData);
}
}.start();
}
private Handler handler = new Handler() {
public void handleMessage(Message message) {
switch (message.what) {
case MESSAGETYPE_01:
//刷新UI,显示数据,并关闭进度条
progressDialog.dismiss(); //关闭进度条
break;
}
}
};
}
更多精彩
赞助商链接