Getting child elements from LinearLayout

后端 未结 7 1077
北恋
北恋 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:14

    You can do like this.

    ViewGroup layoutCont= (ViewGroup) findViewById(R.id.linearLayout);
    getAllChildElements(layoutCont);
    public static final void getAllChildElements(ViewGroup layoutCont) {
        if (layoutCont == null) return;
    
        final int mCount = layoutCont.getChildCount();
    
        // Loop through all of the children.
        for (int i = 0; i < mCount; ++i) {
            final View mChild = layoutCont.getChildAt(i);
    
            if (mChild instanceof ViewGroup) {
                // Recursively attempt another ViewGroup.
                setAppFont((ViewGroup) mChild, mFont);
            } else {
                // Set the font if it is a TextView.
    
            }
        }
    }
    
    0 讨论(0)
提交回复
热议问题