Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 638
user2532233 Avatar asked Jul 19 '13 14:07

user2532233


1 Answers

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

like image 193
Scott Avatar answered Sep 29 '22 08:09

Scott