2011-03-25 46 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