Search code examples
androidandroid-linearlayout

Get all child views inside LinearLayout at once


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


Solution

  • 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.
          // …
    }