1, in many cases, we may not know the ID of the control, but we would like to find it in the view containing the control, you can use the following practices:
Example: Find all of the button controls in the activity's root view
private void Findbutton (ViewGroup group, list<button> result)
{
if (group! = null)
{
for (int i = 0, j = group.getchildcount (); i < J; i++)
{
View child = Group.getchildat (i);
if (Child instanceof Button)
{
Result.add (Button) child);
} else if (child instanceof ViewGroup)
{
Findbutton ((viewgroup) child, result);
}
}
}
}
Called in the activity:
list<button> result = new arraylist<button> ();
This.findbutton ((ViewGroup) This.getwindow (). Getdecorview (), result);
This method is in fact recursively from the root view to find the entire control tree, finally find the control that meets the requirements, a little rewrite can meet the needs of a variety of search control.
Find controls in any view in Android