Reputation: 2316
I have the following hierarchy in my layout:
ScrollView
RadioGroup
RelativeLayout
RadioButton
ImageView
RelativeLayout
RadioButton
ImageView
...
Now the point is, that it looks fine in the XML editor where RadioButtons
and ImageViews
have default values (placeholders) defined, but when I launch an activity and call removeAllViews()
on the RadioGroup
, all ImageViews
disappear. What's interesting, all buttons get new values, only ImageViews
are not updated anyhow (setting new source images gives no results).
So, my question is: does removeAllViews()
erase the child views completely (like they never existed in a layout XML file) or just removes some values leaving the views' arguments to be defined (like setting new source image or new button description)?
Upvotes: 1
Views: 2524
Reputation: 7929
From the official documentation, removeAllViews()
:
Call this method to remove all child views from the ViewGroup.
Calling this method will set all the childs view to null
, so it will remove the child views from itself, and this child becomes not valid (or not considered as child), but not like it never existed in XML file.
This is removeAllViews() code:
public void removeAllViews() {
removeAllViewsInLayout();
requestLayout();
invalidate();
}
As you can see in removeAllViewsInLayout() method, it set the child value to null:
children[i] = null;
Upvotes: 5