我试图在 3 秒后自动关闭 ProgressDialog 框。这是对话框:
ProgressDialog progress = new ProgressDialog(this);
progress.setTitle("Connecting");
progress.setMessage("Please wait while we connect to devices...");
progress.show();
我尝试了几种方法,但我无法让其中任何一种起作用。希望一个简单的时间或任何东西就足够了。谢谢。
最佳答案
如果您正在处理一个长时间运行的任务然后想在之后取消它,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);
更新添加显示/隐藏:
progress.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
theLayout.setVisibility(View.GONE);
}
});
关于android - 如何在设定时间后关闭 ProgressDialog?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29153378/