[英]Progress Dialog not dismissing
在下面的代码中显示进度对话框,延迟为5秒。 5秒后要关闭该对话框,但下面没有发生。
谁能帮我弄错我的地方?
new CountDownTimer(5000, 1000)
{
public void onTick(long millisUntilFinished)
{
// You don't need anything here
dialog= ProgressDialog.show(SchedulerActivity.this,"Delay", "Please wait...."+ millisUntilFinished/1000 + " Second(s)",true);
}
public void onFinish()
{
dialog.dismiss();
}
}.start();
你在打电话
dialog= ProgressDialog.show(SchedulerActivity.this,"Delay", "Please wait...."+ millisUntilFinished/1000 + " Second(s)",true);
在onTick()
方法中。
它将在每个刻度上创建新的进度对话框实例。 这可能会导致您的功能出现问题,在这种情况下您的对话框不会消失。
请尝试以下代码
final ProgressDialog dialog = new ProgressDialog(DynamicView.this);
dialog.setTitle("Delay");
dialog.setMessage("Please wait...." + 5000 / 1000 + " Second(s)");
dialog.setIndeterminate(true);
new CountDownTimer(5000, 1000) {
public void onTick(long millisUntilFinished) {
// You don't need anything here
dialog.setMessage("Please wait...." + millisUntilFinished / 1000 + " Second(s)");
if (!dialog.isShowing())
dialog.show();
}
public void onFinish() {
if (dialog.isShowing())
dialog.dismiss();
}
}.start();
此代码将根据需要运行。
而不是将“进度对话框”的值分配给对话框变量。 创建进度对话框对象,并为其设置标题,如下所示。
ProgressDialog pd = new ProgressDialog(yourActivity.this);
pd.setMessage("what ever message you like");
pd.show();
在onFinish()
请调用pd.dismiss();
如果onTick
显示进度对话框,请在onTick
方法中设置消息,并在此方法中显示进度对话框。
ProgressDialog pd = new ProgressDialog(yourActivity.this);
new CountDownTimer(5000, 1000)
{
public void onTick(long millisUntilFinished)
{
// You don't need anything here
pd.setMessage("what ever message you like");
if (!pd.isShowing())
pd.show();
}
public void onFinish()
{
pd.dismiss();
}
}.start();
滴答滴答叫多次时间,这就是您的对话框没有关闭的原因
实现这个
new CountDownTimer(5000, 1000) {
public void onTick(long millisUntilFinished) {
// You don't need anything here
if(!dialog.isShowing())
{
dialog= ProgressDialog.show(mContext,"Delay", "Please wait...."+ millisUntilFinished/1000 + " Second(s)",true);
}
}
public void onFinish() {
dialog.dismiss();
}
}.start();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.