我试图在3秒后自动关闭ProgressDialog框。这是对话框:
ProgressDialog progress = new ProgressDialog(this);
progress.setTitle("Connecting");
progress.setMessage("Please wait while we connect to devices...");
progress.show();
我尝试过几种方法,但我无法让其中任何一种方法起作用。一个简单的时间或任何事情都可以满足。感谢。
答案 0 :(得分:17)
如果你正在处理一个长时间运行的任务然后想要取消它,那么AsyncTask是可以的,但是等待3秒钟就有点过分了。尝试一个简单的处理程序。
final ProgressDialog progress = new ProgressDialog(this);
progress.setTitle("Connecting");
progress.setMessage("Please wait while we connect to devices...");
progress.show();
Runnable progressRunnable = new Runnable() {
@Override
public void run() {
progress.cancel();
}
};
Handler pdCanceller = new Handler();
pdCanceller.postDelayed(progressRunnable, 3000);
更新了添加show / hide:
progress.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
theLayout.setVisibility(View.GONE);
}
});