1, in very many cases, we may not know the ID of the control, but we want to include this control in the view to find it, can be used for example, 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);
In fact, this approach is recursively starting from the root view to find the entire control tree, finally find the control that meets the requirements, a little rewrite will be able to meet the needs of a variety of search control.
Android Technology--find controls in the casual view of Android