edward
edward

Reputation: 25

The method RemoveAllViews in Android 2.2

I got confused by the Android SDK API. I invoked the GroupView.RemoveAllViews to clean all the child views, however, the UI does not refresh. By the way, I tried the RemoveViewAt(0) several times and A NullReference Exception occured, which means the sub view was removed but the UI does not change. Any help will be appreciated. Thank you so much.

This is part of the source code.

   private TableLayout contentTable;

   @Override
   protected void onLayout(boolean changed, int l, int t, int r, int b) {
      contentTable = new TableLayout(this.getContext());
      for(int  i = 0 ; i < 10 ; i ++)
      {
         TableRaw tr = new  TableRaw(this.getContext());
         Button b = new Button(this.getContext());
         b.setOnClickListener(new OnClickListener(){
               public void onClick(View v) {
           // TODO Auto-generated method stub
           Clean()
           }
         });
         tr.addView(b);
         contentTable.addView(tr);
      }
     super.onLayout(changed, l, t, r, b);
   }

   private void Clean()
   {
      contentTable.removeAllViews();
      this.invalidate();
    }

Upvotes: 0

Views: 3103

Answers (1)

PH7
PH7

Reputation: 3916

You need to invalidate your layout. use invalidate() method to your GroupView.

GroupView.invalidate()

From what I get from your comments.

I believe you have main activity as follow.

public class YourActivity extends Activity {
    testView yourviewGroup;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        yourviewGroup = (testView)findViewById(R.id.yourid);

        /**if you want to clean your viewgroup **/
        yourviewGroup.Clean();
        yourviewGroup.invalidate();
    }
}

Upvotes: 1

Related Questions