2011-03-25 47 views
2

这是怎么了创建PorgressDialog:安卓:无法解雇ProgressDialog

... 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秒我想dimiss对话框,但它不工作:(请帮助。

回答

3

您不能修改从非UI线程UI使用handlers

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); 
+0

好吧,我只是测试多一个方法..其这样:创建你的进步dialoge一样,progressDialoge P = ProgressDialoge.show(myContextVariable”标题”, “消息”);其中myContextVariable在onCreate()中像这样初始化:myContextVariable = this; //这个“这个”非常重要;否则你可能会得到一个错误......现在在处理程序中使用.Cancel函数来取消对话...希望它能够工作... – Farhan 2011-03-25 13:26:46