标签:
1-普通进度对话框
public void bt_8(View v)
{
final ProgressDialog progressDialog=new ProgressDialog(this);
progressDialog.setTitle("提示");
progressDialog.setMessage("请等待……");
progressDialog.setCancelable(false);//防止点击其他地方就关闭
progressDialog.show();
//不在此写业务代码
//开启子线程
//多线程-继承;实现接口
//1-继承Thread,重写里边的方法(run),调用start方法
new Thread(){
@Override
public void run() {
//延时 线程
try {
Thread.sleep(1000);
}
catch (Exception e)
{
}
//打开直接关闭
progressDialog.dismiss();
}
}.start();//负责启动子线程,自动执行run方法
}
2-水平进度对话框
public void bt_9(View v) { final ProgressDialog progressDialog=new ProgressDialog(this); progressDialog.setTitle("水平进度对话框"); progressDialog.setMessage("正在加载……"); progressDialog.setCancelable(false); //设置成水平 progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); progressDialog.show(); final TextView tv_1=(TextView)findViewById(R.id.tv_1); //启动一个子线程 实现接口的方式 Runnable,只有一个方法(run) new Thread(new Runnable() { @Override public void run() { //模拟进度变化 for (int i=0;i<=100;i++) { progressDialog.setProgress(i); //延时 线程 try { Thread.sleep(500); } catch (Exception e) { } } //在子线程里去访问UI线程的View runOnUiThread(new Runnable() { @Override public void run() { tv_1.setText("下载完成"); } }); //打开直接关闭 progressDialog.dismiss(); } }).start(); }
标签:
原文地址:http://www.cnblogs.com/1ming/p/5498377.html