I would like to know what is the difference between View and ViewParent ? I am trying to get the Id of the parent of an ImageView
but this I can't do :
myImageView.getParent().getId();
So is there another way to get this id ?
I would like to know what is the difference between View and ViewParent ? I am trying to get the Id of the parent of an ImageView
but this I can't do :
myImageView.getParent().getId();
So is there another way to get this id ?
Surrounding imageview returns the parent layout id.
example :
A
View
is a class and aViewParent
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 aViewParent
which doesn't directly expose agetId()
method.As others have said, casting the
ViewParent
to aView
using......should work at compile time but be aware of the following...
View
doesn't implement theViewParent
interface then the cast will fail.View
must have a resource id defined in the layout file as (for example)android:id=@+id/myParentViewId
or the call togetId
will returnnull
You have to cast your parent view to a
View
, so you can usegetId()
method, using((View) myImageView.getParent()).getId()