Android - how to remove linear layout view

In my application, I dynamically add a view to a linear layout. each view consists of one button, if you click on it, then the view will be deleted. How to update the linear layout? because when I delete any view, the position of the position will be changed.

+7
source share
8 answers

To remove any kind you can use

ll.removeView(view)// to remove particular view ll.removeViewAt(position);// to remove view from particular position 

Use the following logic to remove any view from the layout

 ll.post(new Runnable() { public void run() { ll.removeView(view); } }); 
+10
source

You doubt it is not clear. But you can try to set the view as visibility = gone.

+4
source

When deleting or adding views, linearlayout needs to measure and compose all of its children again, and that is why they move. You can simply try to set the visibility to invisible.

 myLinearLayout.setVisibility(View.INVISIBLE); 

any view set to invisible retains its size and layout, but can no longer be seen.

+2
source

You tried

 setContentView(R.layout.main); 

after removal?

0
source

How to update a linear layout?

 linearLayoutObject.invalidate() 

How to remove an item from a linear layout?

 linearLayoutObject.removeView(View view); 

or

 linearLayoutObject.removeViewAt(int index); 

Hope this helps.

0
source

use listview with the adapter to dynamically populate the data (due to the fact that it is made), and whenever your data or user interface changes, create a new adapter (data set) and notify the adapter.

0
source

Just use linearLayout.removeView (View view); It will be automatically updated.

0
source

layout.removeAllViewsInLayout (); layout.invalidate ();

I hope this help

0
source

All Articles