title: Android ProgressBar message change when percent is loaded
body: <p>I am trying to add message when the progress bar loads on a specific percent. So when 10 percent is loaded a title or a message appear that something is loaded.
  I cant do it and it forcing to close.
  Any Ideas how to do it.</p>
  
  <p>Below is my sample code</p>
  
  <pre><code>  public void onClick(View v) {
  
          // prepare for a progress bar dialog
          progressBar = new ProgressDialog(v.getContext());
          progressBar.setCancelable(true);
          progressBar.setMessage("File downloading ...");
          progressBar.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
          progressBar.setProgress(0);
          progressBar.setMax(100);
          progressBar.show();
          //getWindow().requestFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
  
          //reset progress bar status
          progressBarStatus = 0;
          //reset filesize
          fileSize = 0;
  
          new Thread(new Runnable() {
            public void run() {
              while (progressBarStatus &lt; 100) {
  
                // process some tasks
                progressBarStatus = doSomeTasks();
  
                // your computer is too fast, sleep 1 second
                try {
                  Thread.sleep(1000);
                } catch (InterruptedException e) {
                  e.printStackTrace();
                }
  
                // Update the progress bar
                progressBarHandler.post(new Runnable() {
                  public void run() {
                    progressBar.setProgress(progressBarStatus);
                  }
                });
              }
  
              // ok, file is downloaded,
              if (progressBarStatus &gt;= 100) {
  
                  // sleep 2 seconds, so that you can see the 100%
                  try {
                      Thread.sleep(2000);
                  } catch (InterruptedException e) {
                      e.printStackTrace();
                  }
  
                  // close the progress bar dialog
                  progressBar.dismiss();
              }
            }
             }).start();
  
             }
  
              });
  
      }
  
  // file download simulator... a really simple
  public int doSomeTasks() {
  
      while (fileSize &lt;= 1000000) {
  
          fileSize++;
          setProgressBarIndeterminate(true);
          if (fileSize == 100000) {
              progressBar.setMessage("10 percent loaded");
              return 10;
          } else if (fileSize == 200000) {
              progressBar.setMessage("20 percent loaded");
              return 20;
          } else if (fileSize == 300000) {
              progressBar.setMessage("30 percent loaded");
              return 30;
          }
          // ...add your own
  
      }
  
      return 100;
  
  }
  </code></pre>
  
  <p>Thanks StackOverFlow users </p>