Android ProgressDialog显示线程处理进度
2010-11-05 00:54:39 来源:WEB开发网isCannel = true;
}
public void onCancel(DialogInterface dialog) {
isCannel = true;
}
}
}
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) {
isCannel = true;
}
public void onCancel(DialogInterface dialog) {
isCannel = true;
}
}
}
Tags:Android ProgressDialog 显示
编辑录入:coldstar [复制链接] [打 印]更多精彩
赞助商链接