Randomizer
Randomizer

Reputation: 131

How to get id of drawable of an imageview?

What I want to do is to get the decimal value of the image resource of an imageview on click.

Example is that a Toast should display "2130837504" which is the id of a drawable.

Upvotes: 0

Views: 2445

Answers (1)

Thanos
Thanos

Reputation: 3665

You can't do that. What you can do is this:

There is no getDrawableId function so you'll need to do something like set a tag for the ImageView when you change its drawable. For instance, set the drawable id as a tag for the ImageView so you could just get the drawable id from the tag.

How to do that?

myImageView.setTag(R.drawable.currentImage);    //When you change the drawable
int drawableId = (Integer)myImageView.getTag(); //When you fetch the drawable id

which is taken from here

Upvotes: 1

Related Questions