How to get all Views in an Activity?
To be specific:
private void show_children(View v) {
ViewGroup viewgroup=(ViewGroup)v;
for (int i=0;i<viewgroup.getChildCount();i++) {
View v1=viewgroup.getChildAt(i);
if (v1 instanceof ViewGroup) show_children(v1);
Log.d("APPNAME",v1.toString());
}
}
And then use the function somewhere:
show_children(getWindow().getDecorView());
to show all Views in the current Activity.
is there a way to get every view that is inside my activity?
Get your root View
, cast it to a ViewGroup
, call getChildCount()
and getChildAt()
, and recurse as needed.
I have over 200 views including buttons, and images, so i want to be able to access them by using a loop
That is a rather large number of Views
.