开发者

Progress Bar Problem

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.

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

How can I handle this?

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() > 0)
        {                                                                                                                               开发者_开发问答                                                                              i             if(RB_Constant.upcomingexits_obj.response.get(0).listRestaurants.size() > 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() > 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 < numItems1; position++)
            {
            View convertview = null;
                convertview = rbupcadapter1.getView(position, convertview, null);                                                                                                     listLayout1.addView(convertview);
            }
            }   
        catch(Exception e)
        {                                        System.out.println("Exit1Listener error ->"+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;
        }

    }
};


you can't update UI(views) objects from other threads except UI thread,try to use Handler object.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜