I would like to know what is the difference between View and ViewParent ?
View is a class and a
ViewParent is an interface.
Although many of the common layout classes implement the
ViewParent interface it isn’t guaranteed.
The problem you’re having is that the
myImageView.getParent() is returning a
ViewParent which doesn’t directly expose a
As others have said, casting the
ViewParent to a
…should work at compile time but be aware of the following…
- If the parent
Viewdoesn’t implement the
ViewParentinterface then the cast will fail.
- The parent
Viewmust have a resource id defined in the layout file as (for example)
android:[email protected]+id/myParentViewIdor the call to
You have to cast your parent view to a
View, so you can use
getId() method, using