Android ProgressDialog显示线程处理进度
2010-11-05 00:54:39 来源:WEB开发网用android进度条监听后台线程的处理进度,适用于网络操作,大文件复制等耗时操作
Java代码
public class main extends Activity {
private static boolean isCannel = false;
private ProgressDialog progressDialog;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
progressDialog = new ProgressDialog (this);
CharSequence title = "ProgressDialog监听线程处理进度";
//CharSequence message = getString(R.string.xxx);
CharSequence message = "当前处理进度";
ProcessThread mThread = new ProcessThread();
progressDialog = new ProgressDialog(this);
progressDialog.setTitle(title);
progressDialog.setMessage(message);
progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progressDialog.setButton((CharSequence)"取消", mThread);
progressDialog.setProgress(0);
progressDialog.setMax(100);
progressDialog.setOnCancelListener(mThread);
progressDialog.setOnDismissListener(mThread);
progressDialog.show();
mThread.start();
}
private class ProcessThread extends Thread implements OnCancelListener, OnDismissListener, OnClickListener{
public void run() {
isCannel = false;
int process = 0;
while(!isCannel && process < 100) {
progressDialog.incrementProgressBy(1);
try {
sleep(200);
} catch (InterruptedException e) {
e.printStackTrace();
}
process ++;
}
progressDialog.dismiss();
finish();
}
public void onClick(DialogInterface dialog, int which) {
isCannel = true;
}
public void onDismiss(DialogInterface dialog) {
Tags:Android ProgressDialog 显示
编辑录入:coldstar [复制链接] [打 印]- ››Android 当修改一些代码时,使用什么编译命令可以最...
- ››Android 如何添加一个apk使模拟器和真机都编译进去...
- ››Android 修改Camera拍照的默认保存路径
- ››Android 如何修改默认输入法
- ››android开发中finish()和System.exit(0)的区别
- ››Android手势识别简单封装类
- ››android中查看项目数字证书的两种方法
- ››Android中获取IMEI码的办法
- ››android 相机报错 setParameters failed
- ››Android重启运用程序的代码
- ››Android为ListView的Item设置不同的布局
- ››android bitmap与base64字符串的互相转换
更多精彩
赞助商链接