Getting child elements from LinearLayout

后端 未结 7 1158
北恋
北恋 2020-12-08 09:13

Is there a way to obtain a child element of a LinearLayout? My code returns a view (linearlayout), but I need to get access to specific elements inside of the layout.

<
7条回答
  •  孤城傲影
    2020-12-08 10:00

    LinearLayout layout = (LinearLayout)findViewById([whatever]);
    for(int i=0;i

    If they are all buttons, otherwise cast to view and check for class

    View v =  (View)layout.getChildAt(i);
    if (v instanceof Button) {
         Button b = (Button) v;
    }
    

提交回复
热议问题