is there a way to get every view that is inside my activity? I have over 200 views including buttons, and images, so i want to be able to access them by using a loop
for example something like
for (View v : this)
{
//do something with the views
//depending on the types (button, image , etc)
}
The DecorView is the view that actually holds the window's background drawable. Calling getWindow(). setBackgroundDrawable() from your Activity changes the background of the window by changing the DecorView's background drawable.
SetContentView(View) Set the activity content to an explicit view. SetContentView(Int32) Set the activity content from a layout resource. SetContentView(View, ViewGroup+LayoutParams)
An activity represents a single screen with a user interface just like window or frame of Java. Android activity is the subclass of ContextThemeWrapper class. The Activity class defines the following call backs i.e. events. You don't need to implement all the callbacks methods.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With