Android: get Viewgroup from the view? Android: get Viewgroup from the view? android android

Android: get Viewgroup from the view?


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