Reputation:
In an activity
I am changing one of the ViewGroup
content runtime: buttons action, other events.
At a specific case I need to check if a child is in this layout
or not ( in this case the child is another RelativeLayout
, which hold other views)
How can I check runtime, programmatically if child_1_RelativeLayout
is there or is already removed from view tree, his parent is parentRelativeLayout
The getParent() is usefully? - not much explanation how to use it, thanks.
Upvotes: 0
Views: 853
Reputation: 1458
In case you have stored your views you can use getParent() to check if view is a direct child for other view. After removing view its parent field will be cleared. For example:
ViewGroup parent = ...;
View child = ...;
assert(child.getParent() == parent); // <-- true
parent.removeView(child);
assert(child.getParent() == parent); // <-- false
Upvotes: 2
Reputation: 1352
Not really sure if I understand your question correctly, but:
ViewGroup
, use ViewGroup's findViewById()
method (inherited from View
) and pass it the id you've given to the relative layoutfindViewById()
will find itSo in short, findViewById()
is not only defined for an Activity, but you can call this on any view you would like to use as a starting point for your search.
Upvotes: 1