WEB开发网
开发学院手机开发Android 开发 Android ProgressDialog显示线程处理进度 阅读

Android ProgressDialog显示线程处理进度

 2010-11-05 00:54:39 来源:WEB开发网   
核心提示:用android进度条监听后台线程的处理进度,适用于网络操作,Android ProgressDialog显示线程处理进度,大文件复制等耗时操作Java代码public class main extends Activity {private static boolean isCannel = false;privat

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) {

1 2  下一页

Tags:Android ProgressDialog 显示

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