There is no method that will give you ImageResource
.
You can check ImageView source code. They just convert your ImageResource to Drawable and use it. So you have a getter method for Drawable imageView.getDrawable();
. This is only what you can get. There is no getter for getting resource id from Drawable
object.
if (mResource != 0) {
try {
d = mContext.getDrawable(mResource);
} catch (Exception e) {
Log.w(LOG_TAG, "Unable to find resource: " + mResource, e);
// Don't try again.
mResource = 0;
}
}
Solution 1 From ref
If you want pass Image to another Activity, you can do this.
When you set ImageView resource in Adapter then set a Tag on this.
imageView0.setTag(R.drawable.apple);
Now when you want get that id when user click, then only do
private int getDrawableId(ImageView iv) {
return (Integer) iv.getTag();
}
Solution 2
If you are one setting ImageView resource, then you would have this resource integer in your List?, so when user click then get resource again like
yourList.get(getAdapterPosition).getImageId();