Android: Iterate Through a Views Child Views

2/21/2014 2:38:52 AM

The following gets a layout and iterates through all child views and then iterates through the childs, child views.

LinearLayout layoutMyLayout = (LinearLayout) findViewById(R.id.myLayout);
if (layoutMyLayout != null)
{
	for (int x = 0; x < layoutMyLayout.getChildCount(); x++)
	{
		View viewChild1 = layoutMyLayout.getChildAt(x);
		Class classChild1 = viewChild1.getClass();
		if (classChild1 == LinearLayout.class)
		{
			LinearLayout layoutChild1 = (LinearLayout) viewChild1;
			for (int y = 0; y < layoutChild1.getChildCount(); y++)
			{
				//continue
			}
		}
	}
}