Get all child views inside LinearLayout at once

Adham picture Adham · Oct 16, 2011 · Viewed 105.2k times · Source

I have a LinearLayout, which contains several child TextViews. How can I get child views of that LinerLayout using a loop?

Answer

Yashwanth Kumar picture Yashwanth Kumar · Oct 16, 2011

Use getChildCount() and getChildAt(int index).

Example:

LinearLayout ll = …
final int childCount = ll.getChildCount();
for (int i = 0; i < childCount; i++) {
      View v = ll.getChildAt(i);
      // Do something with v.
      // …
}