2013-02-06 6 views
6

Ist es möglich, den progressDialog-Text zu ändern?Android: Ändern des Fortschritts Dialogfeldtext

mein Code:

progressDialog = ProgressDialog.show(BackupActivity.this, "In progress", "test1"); 
          new Thread() { 
           public void run() { 
            try{ 
             sleep(10000); 
              } catch (Exception e) { 
               Log.e("tag", e.getMessage()); 
              } progressDialog.dismiss(); 
           } 
          }.start(); 
         } 
        }); 
        selectExportsDialog = builder.create(); 
       } 
       selectExportsDialog.show(); 
       break;   } 

Ich möchte test1 ändern, nachdem beispielsweise 10 Sekunden bis test2. Möglich?

Dank

Antwort

8

, die feine Arbeit ist: mit diesem Code

runOnUiThread(changeText); 

:

private Runnable changeText = new Runnable() { 
    @Override 
    public void run() { 
     m_ProgressDialog.setMessage(myText); 
    } 
}; 
+0

funktioniert wie erwartet! – Davide

+0

Ich bin froh, Ihnen zu helfen :) – jlopez

+1

Zeigen Sie immer die Referenz, wo Sie von http://stackoverflow.com/questions/3947080/progressdialog-does-not-want-to-update-the-message kopiert haben –

4

Sie können dies versuchen:

private class ProgressRunner extends AsyncTask<URL, Integer, Long> 
    { 
     protected void onPreExecute() 
     { 
      try  
      { 
       dialog = new ProgressDialog(context); 
       dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); 
       dialog.setTitle("TITLE"); 
       dialog.setMessage("MY TEXT 1"); 
       dialog.setCancelable(false); 
       dialog.setProgress(0);    
       dialog.setIndeterminate(false); 
       dialog.show();    
      } 
      catch (Exception e) 
      {    
       e.printStackTrace(); 
       dialog.dismiss(); 
      } 
     } 


     @Override 
     protected void onCancelled() 
     { 
      super.onCancelled(); 
      dialog.dismiss();   
     } 


     @Override 
     protected Long doInBackground(URL... params) 
     { 
      // process the code here 
      dialog.setMessage("MY TEXT 2"); 
      return null; 
     } 

     protected void onProgressUpdate(Integer... progress) 
     {   
      dialog.setProgress(progress[0]); 
     }  

     protected void onPostExecute(Long result) 
     { 
      try 
      {        
       dialog.dismiss();   

      } 
      catch (Exception e) 
      {    
       e.printStackTrace(); 
       finish(); 
      }  
     } 
    } 
Verwandte Themen