Getting child elements from LinearLayout

后端 未结 7 1157
北恋
北恋 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 09:51

    One of the very direct ways is to access the child views with their ids.

    view.findViewById(R.id.ID_OF_THE_CHILD_VIEW)
    

    here view is the parent view.

    So for instance your child view is an imageview, with id, img_profile, what you can do is:

    ImageView imgProfile = view.findViewById(R.id.img_profile)
    

提交回复
热议问题