Android: How to get the ID of a parent View?

android

Solution

`ViewParent` is just an interface that any View that can have children implements. Most of the times the class you get back will be an instance of a `ViewGroup`, like `LinearLayout` or `RelativeLayout`. I'm not exactly sure what you mean by "name" but if you want to get the class name you can do so like always: `view.getParent().getClass().getName()`.

Problem

`View.getRoot()` returns `View`, so we can easily figure out which is the root view by using `getResourceName(View.getId())`. `View.getParent()`..., while I expect it also returns `View` that is the parent, actually only returns an instance of `ViewParent` that seems to have very very few useful method/fields. It sucks. So, is there any way to know the ID of the parent? I believe a `View`'s parent is also `View`, thus it should has mID field. I really wonder why Google didn't let `View.getParent()` just returns `View`. It makes sense, only when something else other than `View` could be the parent, and as far as I know, it's limited to `View` and its subclasses.

Original source