2011-04-19 33 views

回答

0

添加取消按鈕進度對話框。也許這些幫助Why is there no cancel button in Android's progress dialogs?

而你應該使用線程和處理程序來做你想做的。

ProgressDialog dialog = ProgressDialog.show(MyActivity.this, "", 
        "Loading. Please wait...", true); 

Thread t = new Thread(new Runnable() { 

     @Override 
     public void run() { 
      // TODO Auto-generated method stub 
     dialog.Show(); 

     } 
    }); 


t.Start(); 
@Override 
public void onBackPressed() { 
    // TODO Auto-generated method stub 
    super.onBackPressed(); 
      handler.sendemptymessage(0); 
} 

private Handler hanlder = new Handler(){ 
    public void handleMessage(Message msg) { 
     t.Stop(); 
     //dialog.dismiss(); try these if stoping thread don't work 

    } 

}; 
+0

我不這麼認爲添加按鈕,將解決我的問題,因爲如果一個人按下返回鍵,而不是按鈕,然後我的線程會去後臺... :) – 2011-04-19 06:57:51

+0

@Coder_sLay看到我的代碼,在那裏 – PedroAGSantos 2011-04-19 07:15:58

+0

和你有一個谷歌樣本幾乎你想要的:) – PedroAGSantos 2011-04-19 07:22:14

相關問題