2012-03-20 57 views
0

我需要幫助,我的DIALOG_DOWNLOAD_PROGRESS始終顯示onPreExecute()(第二次下載嘗試)100%。如何使它從第二次嘗試下載的0%開始。在這裏需要幫助。由於DIALOG下載進度始終顯示100%的第二次下載嘗試

@Override 
protected Dialog onCreateDialog(int id) { 
    switch (id) { 
    case DIALOG_DOWNLOAD_PROGRESS: 
     mProgressDialog = new ProgressDialog(this); 
     mProgressDialog.setMessage("Downloading file.."); 
     mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); 
     mProgressDialog.setCancelable(true); 
     mProgressDialog.show(); 
     return mProgressDialog; 
    default: 

     return null; 
    } 
} 

類DownloadFileAsync擴展的AsyncTask {

@Override 
protected void onPreExecute() { 
    super.onPreExecute(); 
    showDialog(DIALOG_DOWNLOAD_PROGRESS); 
} 

....

} 
protected void onProgressUpdate(String... progress) { 
    Log.d("ANDRO_ASYNC",progress[0]); 
    mProgressDialog.setProgress(Integer.parseInt(progress[0])); 

} 

@Override 
protected void onPostExecute(String unused) { 
    dismissDialog(DIALOG_DOWNLOAD_PROGRESS); 
} 

回答

0

因爲onCreateDialog只調用一次創建對話框,你就必須重新設置對話框在onPrepareDialog中,每次在對話框顯示前調用它。

@Override 
protected void onPrepareDialog(int id, Dialog dialog, Bundle args) 
    if (id == DIALOG_DOWNLOAD_PROGRESS) 
     mProgressDialog.setProgress(0); 
} 
+0

謝謝,它的工作 – 2012-03-20 02:21:19

0
protected Dialog onCreateDialog(int id){ 

     switch(id){ 

      case 0: 

       _progressDialog = new ProgressDialog(null); 


       _progressDialog.setTitle("Downloading files.."); 

       _progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); 

       _progressDialog.setButton(DialogInterface.BUTTON_POSITIVE, "Hide", new DialogInterface.OnClickListener() { 



       @Override 

       public void onClick(DialogInterface dialog, int which) { 

         Log.d(TAG, "hide"); 

        } 

       }); 

       _progressDialog.setButton(DialogInterface.BUTTON_NEGATIVE, "Cancel", new DialogInterface.OnClickListener() { 

         @Override 

        public void onClick(DialogInterface dialog, int which) { 

         Log.d(TAG, "cancel"); 

         cancelLoad(); 

        } 

         private void cancelLoad() { 
          // TODO Auto-generated method stub 

         } 

       }); 

     } 

     return _progressDialog; 

    } 
+0

這裏是我的對話下載進度工作的代碼,但沒有出現對話框,不知道是什麼問題,我求你了誰可以幫我轉告一下問題是爲什麼不顯示對話。 – Lars 2013-06-21 19:37:20