WEB开发网
开发学院手机开发Android 开发 Android 连接网络时显示进度条 阅读

Android 连接网络时显示进度条

 2010-08-31 00:06:00 来源:WEB开发网   
核心提示:public class HelloXML extends Activity {private static final int MESSAGETYPE_01 = 0x0001;private ProgressDialog progressDialog = null;@Overridepublic void onCre

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;

}

}

};

}

Tags:Android 连接 网络

编辑录入:coldstar [复制链接] [打 印]
赞助商链接