2011-02-27 48 views
0

在我的應用我試圖顯示採取一個函數來完成它的執行,並關閉它一個時間進度的函數執行完成後...Android:顯示進度條對話框時出現問題?

我的代碼定義如下:

protected Dialog onCreateDialog(int id) { 
     switch (id) { 
      case PROCESS: { 
       ProgressDialog dialog = new ProgressDialog(this); 
       dialog.setTitle("Indeterminate"); 
       dialog.setMessage("Please wait while loading..."); 
       dialog.setIndeterminate(true); 
       dialog.setCancelable(true); 
       return dialog; 
      } 
     } 
     return null; 
    } 




showDialog(PROCESS); 
doFunction(); 
dismissDialog(PROCESS); 

,由於某種原因未未顯示processdialog ...

能有人幫我在這裏請.... 是否有任何其他的方式來做到這一點...

謝謝:)

回答

2

由於您的功能需要一定的時間來處理,使用異步任務

new AsyncTask<Void, Void, Void>() { 

     @Override 
     protected void onPreExecute() 
     { 
      pd = ProgressDialog.show(getApplicationContext(),"", "Sending Image ...", true); 
      Log.d(TAG, "onPreExecute()"); 
     } 

     @Override 
     protected Void doInBackground(Void... params) 
     { 
      doFunction(); 
      return null; 
     } 

     @Override 
     protected void onPostExecute(Void res) 
     { 
      Log.d(TAG, "onPostExecute()"); 
      pd.dismiss(); 
     } 
    }.execute(); 

它其次設置爲不確定意味着你只能看到一個圓啄。

您應該設置progress styleSTYLE_HORIZONTAL

+0

我都試過,但我得到像......「android.view.WindowManager $ BadTokenException錯誤:無法添加窗口 - 令牌null不是一個應用程序'....你能幫我出去的人.... – kAnNaN 2011-02-27 14:12:59