android - update progressbar
<p>I would like to update spinner object after I get a google calendar name in a different thread. When I execute this, it crashes.  I am not sure if I need to make it work with a different approach or if there is something wrong with it.</p>

<pre><code>private void updateGoogleCalendar() {
  try {
      Thread.sleep(4000);
      List&lt;String&gt; list = new ArrayList&lt;String&gt;();
      list.add("Sample Calendar");
      updatedCalendarNames = list.toArray(new String[0]);
      progressBar.dismiss();

    } catch (InterruptedException e) {
      e.printStackTrace();
    }
}
 public void initializeWidgets() {
    final Spinner spinner = (Spinner) layout.findViewById(R.id.googleCalendarSelection);
    final Button refreshCalendarBtn = (Button) layout.findViewById(R.id.refreshCalendarBtn);
    refreshCalendarBtn.setOnClickListener(new OnClickListener() {
       @Override
         public void onClick(View v) {
         progressBar = ProgressDialog.show(getContext(), "", "Loading...");
         new Thread(new Runnable() {

       @Override
         public void run() {
         updateGoogleCalendar();
         final ArrayAdapter&lt;CharSequence&gt; adapter = new ArrayAdapter&lt;CharSequence&gt;(getContext(), android.R.layout.simple_spinner_item);
         adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
         spinner.setAdapter(adapter);
         while (updatedCalendarNames == null) {
           try {
               Thread.sleep(500);

             } catch (InterruptedException e) {
               e.printStackTrace();
             }
        }
            for (String calendarName : updatedCalendarNames) {
            CharSequence charSequence = calendarName + "";
            adapter.add(charSequence);
          }                     
            }
         }).start();
       }
    });
  }
</code></pre>
