Reputation: 10392
In my application i am adding the view dynamically to the linear layout. each view consists of one button if you click on that then view will be deleted. How to refresh the linear layout? because when i removed any view then the view's positions will be changed.
Upvotes: 16
Views: 27614
Reputation: 53647
LinearLayout ll = findViewById(R.id.yourLinearLayout);
To remove any view you can use
ll.removeView(view)// to remove particular view
ll.removeViewAt(position);// to remove view from particular position
Use following logic to remove any view from layout
ll.post(new Runnable() {
public void run() {
ll.removeView(view);
}
});
Upvotes: 24
Reputation: 41
layout.removeAllViewsInLayout(); layout.invalidate();
I hope this help
Upvotes: 4
Reputation: 29199
Simply Use linearLayout.removeView(View view); It would refresh automaically.
Upvotes: 0
Reputation: 4069
use listview with Adapter to fill the data dynamically (because that's what for they are made) and whenever your data or UI gets changed create new adapter (data set) and notify the adapter about change.
Upvotes: 0
Reputation: 5900
By removing or adding views the linearlayout has to measure and layout all its children again which is why they move. You could simply try setting the visibility to invisible.
myLinearLayout.setVisibility(View.INVISIBLE);
any view set to invisible still retains its size and positioning in the layout but can no longer be seen.
Upvotes: 2
Reputation: 2679
How to refresh the linear layout?
linearLayoutObject.invalidate()
How to remove item from the linear layout?
linearLayoutObject.removeView(View view);
or
linearLayoutObject.removeViewAt(int index);
I hope it helps..
Upvotes: 2
Reputation: 38168
You question is not that clear. But you could try setting the view as visibility = gone.
Upvotes: 6