Get all child views inside LinearLayout at once

前端 未结 6 2176
野性不改
野性不改 2020-11-28 04:39

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

6条回答
  •  长情又很酷
    2020-11-28 05:29

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

提交回复
热议问题