【问题标题】:Android: Unable to Dismiss ProgressDialogAndroid:无法关闭 ProgressDialog
【发布时间】:2011-03-25 11:56:14
【问题描述】:

这就是我创建 PorgressDialog 的方式:

... progressBarDialog = new ProgressDialog( context );
                  progressBarDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progressBarDialog.show(this, "Please Wait", "Updating your GPS coordinates",false,true);


//Trigger GPS service to update coordinates
fg.myOnresume(Name);
fg.dontSendSMS();
//Sets the timer at 30 secs
timer= new Timer();
timer.schedule(new startMapActivity());
}
class startMapActivity extends TimerTask 
    {
        @Override
        public void run() 
        {
            //handler.sendEmptyMessage(0);
            Log.d("", "StartMapActivty--->>>run()");
            // Dismissing Dialog Box
            if(progressBarDialog.isShowing())
            {
                progressBarDialog.dismiss();
            }

        }
    }

所以基本上在 30 秒后计时器完成后,我想关闭对话框,但它不起作用:(请帮忙。

【问题讨论】:

    标签: android progressdialog dismiss


    【解决方案1】:

    您不能从非 UI 线程修改 UI。使用handlers 进行操作。

    【讨论】:

      【解决方案2】:

      稍微修改一下你的代码。喜欢:

          Runnable r = new Runnable()
          {
      
              public void run() 
              {
                 // TODO Auto-generated method stub
                 //dismiss your dialoge here....
              }
          };
      

      你可以这样称呼它:

        Handler h = new Handler();
        h.postDelayed(r, delayMillis);
      

      【讨论】:

      • 好吧,我只是测试了一种方法.. 它是这样的:创建你的进度对话框,progressDialoge p = ProgressDialoge.show(myContextVariable,"title","message");其中 myContextVariable 在 onCreate() 中像这样初始化: myContextVariable = this; // 这个“this”很重要;否则你可能会得到一个错误......现在在处理程序中使用 .Cancel 函数来取消对话......希望它有效......
      【解决方案3】:

      检查这个线程: ProgressDialog dismissal in android

      【讨论】:

        猜你喜欢
        • 2015-05-12
        • 1970-01-01
        • 2011-06-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-04-10
        • 1970-01-01
        • 2021-10-23
        相关资源
        最近更新 更多