Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to refresh the linear layout programmatically

My application has one LinearLayout that LinearLayout consists of the 3 Linearlayouts and that each linear layout has one Relativelayout and one linear layout(initially the visibility of these linear layouts is gone). If you click on the relative layout then the regarding linear layout will be displayed. But how to refresh the entire linear layout after clicking on the relative layout.

Code:

private OnClickListener exit2Listener = new OnClickListener()
{
    public void onClick(View v)
    {
       if(!exit2status)
       {
          if(RB_Constant.upcomingexits_obj.response.size() > 1)
          {
             if(RB_Constant.upcomingexits_obj.response.get(1).listRestaurants.size() > 0)
             {
                 // Create the views on the fly instead of using the ListView
                 UpcomingResultsListViewAdapter2 rbupcadapter2 = new UpcomingResultsListViewAdapter2(RB_UpcomingExits.this);
                 int numItems2 = 0;

                 if(RB_Constant.upcomingexits_obj.response.get(1).listRestaurants.size() > 0)
                 {
                    numItems2 = RB_Constant.upcomingexits_obj.response.get(1).listRestaurants.size();
                 }

                 //linearLayout2
                 for(int position=0; position < numItems2; position++)
                 {
                    View convertview = null;
                    convertview = rbupcadapter2.getView(position, convertview, null);
                    listLayout2.addView(convertview);
                 }
             }              
          }
          else
          {
             //toastMsg("No results!");
          }
          listLayout2.setVisibility(View.VISIBLE);
          exit2status=true;

          if(!exit1status || exit3status || exit4status || exit5status)
          {
             //System.out.println("exit2 GONE");
             listLayout1.setVisibility(View.GONE);
             listLayout3.setVisibility(View.GONE);
             exit1status = false;
             exit3status = false;

          }

          LLExitDetails.invalidate();
       }
       else
       {
          System.out.println("exit2 GONE");
          listLayout2.setVisibility(View.GONE);
          exit2status = false;

          LLExitDetails.invalidate();
       }
    }       
};
like image 842
naresh Avatar asked Jul 06 '11 12:07

naresh


1 Answers

Retrieve the LinearLayout that contains everything. When you need to "refresh" it, call invalidate. Only call it in the UI thread though. If you call it in another thread (say a timer), then call postInvalidate. Both cause the View's onDraw method to be called when the OS is ready to call it.

like image 149
DeeV Avatar answered Sep 23 '22 18:09

DeeV