Android网络加载时显示进度条
1.声明变量
private Handler handler = new Handler(); private ProgressDialog progressDialog = null;
2.在需要网络加载时显示进度条对话框
progressDialog = ProgressDialog.show(MyActivity.this, "请稍等...", "获取数据中...", true);
3.构建Runnable对象,在runnable中更新界面
final Runnable runnableUi=new Runnable() { @Override public void run() { //do some work } };
4.在子线程中的run方法调用UI线程handler.post 来更新UI
new Thread() { @Override public void run() { handler.post(runInUIThread); progressDialog.dismiss(); } }.start();