简体   繁体   中英

Android: get Viewgroup from the view?

Is there any way to get the ViewGroup from a view? I'm trying to create a custom array adapter and it needs the viewgroup

Depending on which ViewGroup you are after, you can get the parent of your view and cast it to a ViewGroup :

(ViewGroup)view.getParent() // this can be done to get any level in your view hierarchy 

or you can cast the view itself as a ViewGroup :

(ViewGroup)view

Basically, find the view you want in your view hierarchy and cast it to ViewGroup

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM