Progress Bar Problem
<p>Initially my application displays 5 Relative Layouts. If you click on a Relative Layout a Linear Layout is loaded; at this point I want to display the progress bar. </p>

<p>I used the following code for the progress bar but I am getting the exception
<code>&gt;android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.</code></p>

<p>How can I handle this?</p>

<p><strong>Code</strong></p>

<pre><code> private OnClickListener exit1Listener = new OnClickListener()
 {
     public void onClick(View v)
     {
    if(!exit1status)
        {
            System.out.println("exit1 visible");
        // Exit1 Restaurants
        if(RB_Constant.upcomingexits_obj.response.size() &gt; 0)
        {                                                                                                                                                                                                             i             if(RB_Constant.upcomingexits_obj.response.get(0).listRestaurants.size() &gt; 0)
          {
              //YRS: listview1.setAdapter(new UpcomingResultsListViewAdapter1(this));
              // Create the views on the fly instead of using the ListView
               rbupcadapter1 = new UpcomingResultsListViewAdapter1(RB_UpcomingExits.this);      


               if(RB_Constant.upcomingexits_obj.response.get(0).listRestaurants.size() &gt; 0)
               {
          numItems1 = RB_Constant.upcomingexits_obj.response.get(0).listRestaurants.size();
       }

    Exitexpand_pd = ProgressDialog.show(RB_UpcomingExits.this, "", "Please wait...", true);
        Thread t = new Thread() 
    {
       public void run() 
       {
        try 
        {   
            for(position=0; position &lt; numItems1; position++)
            {
            View convertview = null;
                convertview = rbupcadapter1.getView(position, convertview, null);                                                                                                     listLayout1.addView(convertview);
            }
            }   
        catch(Exception e)
        {                                        System.out.println("Exit1Listener error -&gt;"+e.toString());
        }                               rb_Exitexpand_Handler.post(null);
    Exitexpand_pd.dismiss();
    }                                               
 };
 t.start(); 


                    //listview1.setMinimumHeight(2000);
                }
            }
            else{
                //toastMsg("No results!");
            }

            listLayout1.setVisibility(View.VISIBLE);
            exit1status = true;
            if(exit2status || exit3status || exit4status || exit5status)
            {
                //System.out.println("exit2 GONE");
                listLayout2.setVisibility(View.GONE);
                listLayout3.setVisibility(View.GONE);
                listLayout4.setVisibility(View.GONE);
                listLayout5.setVisibility(View.GONE);
            }
        }
        else
        {
            System.out.println("exit1 GONE");
            listLayout1.setVisibility(View.GONE);   
            exit1status = false;
        }

    }
};
</code></pre>
