2011-06-23 3 views
3

文字列やその他の文字列を循環するダミータイマーを使用して、進行ダイアログでsetmessageダイアログを変更する方法を知りたい人は、方法。例えば、ロード中にLoading ... - > Building ... - > Rendering ... - > ectと言うことができます。 1/2秒タイマーのように(これは私がそれを使って遊ぶためのもので、ダイアログを変更する方法を見つけたらリアルタイム更新を使用することができます)進捗スレッドからオリエンテーションを差し引いたものを使用していますコード。何か案は?Android:Progress Dialogの変更ProgressDialog.setMessage()ロード中

ありがとうございました!

それはかなりありませんが、私はこれで動作するようにそれを得ることができました:

public class BadBaconJoke extends Activity implements OnClickListener { 
    ProgressDialog dialog; 
    int increment; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.progressdialog); 

     Button startbtn = (Button) findViewById(R.id.startbtn); 
     startbtn.setOnClickListener(this); 
    } 

    public void onClick(View view) { 

     // get the increment value from the text box 
     EditText et = (EditText) findViewById(R.id.increment); 
     // convert the text value to a integer 
     increment = Integer.parseInt(et.getText().toString()); 
     dialog = new ProgressDialog(this); 
     dialog.setCancelable(true); 
     dialog.setTitle("Loading..."); 
     dialog.setMessage("Almsot done!"); 
     // set the progress to be horizontal 
     dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); 

     // reset the bar to the default value of 0 
     dialog.setProgress(0); 

     // get the maximum value 
     EditText max = (EditText) findViewById(R.id.maximum); 
     // convert the text value to a integer 
     final int maximum = Integer.parseInt(max.getText().toString()); 
     // set the maximum value 
     dialog.setMax(maximum); 
     // display the progressbar 
     dialog.show(); 


     // create a thread for updating the progress bar 
     Thread background = new Thread (new Runnable() { 
      public void run() { 
       try { 


        // enter the code to be run while displaying the progressbar. 
        // 
        // This example is just going to increment the progress bar: 
        // So keep running until the progress value reaches maximum value 
        while (dialog.getProgress()<= dialog.getMax()) { 
         // wait 500ms between each update 
         Thread.sleep(500); 

         // active the update handler 
         progressHandler.sendMessage(progressHandler.obtainMessage()); 


        } 
       } catch (java.lang.InterruptedException e) { 
        // if something fails do something smart 
       } 
      } 
     }); 

     // start the background thread 
     background.start(); 



    } 

    // handler for the background updating 
    Handler progressHandler = new Handler() { 
     public void handleMessage(Message msg) { 
      dialog.incrementProgressBy(increment); 
      int x; 
      x = dialog.getProgress(); 

      switch (x) { 
      case 10: dialog.setMessage("Gathering Data");  break; 
      case 20: dialog.setMessage("Parsing Results");  break; 
      case 30: dialog.setMessage("Builindg Data");  break; 
      case 40: dialog.setMessage("TeraForming");  break; 
      case 50: dialog.setMessage("Contacting Server"); break; 
      case 60: dialog.setMessage("Ping Back"); break; 
      case 70: dialog.setMessage("Processing"); break; 
      case 80: dialog.setMessage("Communicating with Device"); break; 
      case 90: dialog.setMessage("Populating"); break; 
      case 100: dialog.setMessage("Displaying Data:"); break; 
      default: dialog.setMessage("..."); break; 
     } 

     if (x == 100){ 
      new AlertDialog.Builder(BadBaconJoke.this); 
      dialog.setTitle("Complete"); 
      //.setMessage("Are you sure you want to exit?") 
      // dialog.setButton(android.R.string.no, null); 
      //.setMessage("Are you sure you want to exit?") 
     } 


     } 
    }; 










} 

任意のアイデアはどのように取得することは、プロセスダイアログ対スピンナーで動作しますか?私がdialog.setProgressStyleを変更すると(ProgressDialog.STYLE_HORIZONTAL);ダイアログに.setProgressStyle(ProgressDialog.STYLE_SPINNER);

スイッチケースのデフォルト値のみが表示されます。

答えて

3

このメソッドはUIスレッドで実行されるため、メッセージを変更するにはonProgressUpdated()を使用できます。ただし、特定の時間内にメッセージを変更する機会はありません。

関連する問題