2

这就是我创建 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 秒后计时器完成后,我想关闭对话框,但它不起作用:(请帮忙。

4

3 回答 3

3

您不能从非 UI 线程修改 UI。使用处理程序来做到这一点。

于 2011-03-25T12:01:17.430 回答
1

稍微改变你的代码。喜欢:

    Runnable r = new Runnable()
    {

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

你可以这样称呼:

  Handler h = new Handler();
  h.postDelayed(r, delayMillis);
于 2011-03-25T12:32:40.347 回答
0

检查这个线程: ProgressDialogdismissal in android

于 2011-03-25T12:04:59.553 回答