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);
This approach, in effect, is to recursively find the entire control tree from the root view and finally find the control that meets the requirements. A little rewriting will be able to meet the needs of various search controls.
Android Technology--find controls in the casual view of Android