Jonny
Jonny

Reputation: 16298

Android: Remove view from superview

How do I remove a View from its superview? In iOS it's performed by sending removeFromSuperview to the view that should be removed.

Upvotes: 16

Views: 5050

Answers (1)

Cat
Cat

Reputation: 67502

You can use getParent() to get the parent of the View, then call removeView() on it.

View yourView = ...;
ViewGroup viewParent = (ViewGroup) yourView.getParent();
viewParent.removeView(yourView);

Upvotes: 31

Related Questions