Adham Adham - 3 months ago 4
Android Question

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?

Answer

Use getChildCount() and also getChildAt().

Example:

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