title: How to update view after done with the progress bar?
body: <p><strong>CASE:</strong> I have a button and list-view in the activity. On click of the button I have added a click listener, which starts a new thread in which I update the progress bar. After the job is done i.e. progress bar is done 100%, I want to update the list-view.</p>
  
  <pre><code>final OnClickListener mStartScan = new OnClickListener() {
  
      @Override
      public void onClick(View v) {
  
          // prepare for a progress bar dialog
          progressBar = new ProgressDialog(v.getContext());
          progressBar.setCancelable(false);
          progressBar.setMessage(getString(R.string.text_scanning_inbox));
          progressBar.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
          progressBar.setProgress(0);
          progressBar.setMax(totalSms);
          progressBar.show();
  
          progressBarStatus = 0;
  
          Thread progressThread = new Thread(new Runnable() {
              public void run() {
                  while (progressBarStatus &lt; totalSms) {
  
                      // process some tasks
                      progressBarStatus = someStuff();
  
                      // Update the progress bar
                      progressBarHandler.post(new Runnable() {
                          public void run() {
                              progressBar.setProgress(progressBarStatus);
                          }
                      });
                  }
  
                  if (progressBarStatus &gt;= done) {
  
                      // sleep 1 seconds, so that you can see the 100%
                      try {
                          Thread.sleep(5000);
                      } catch (InterruptedException e) {
                          e.printStackTrace();
                      }
  
                      // close the progress bar dialog
                      progressBar.dismiss();
  
                      // this method updates the list
                      populateList();
                  }
              }
          });
          progressThread.start();
  
  //          try {
  //              progressThread.join();
  //          } catch (InterruptedException e) {
  //              // TODO Auto-generated catch block
  //              e.printStackTrace();
  //          } finally {
  //              populateList();
  //          }           
          }
  };
  </code></pre>
  
  <p><strong>PROBLEM:</strong> When I update the listview after completion of the task and dismissing progress bar, I get an exception which says that the view can be updated only from the thread in which it is created. </p>
  
  <pre><code>android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
  </code></pre>
  
  <p><strong>WHAT ELSE I TRIED:</strong> I tried waiting for the thread which is running progress bar to complete and then update listview from the main thread. </p>
  
  <pre><code>try {
      progressThread.join();
  } catch (InterruptedException e) {
      e.printStackTrace();
  } finally {
      populateList();
  }
  </code></pre>
  
  <p>However, this does not work. It does not show the progress bar at all.</p>