Abaza Youssef
Abaza Youssef

Reputation: 53

How to retrieve the drawable name using id?

I have an ImageView that changes depending on what Imagebutton was clicked so I was trying to get the name of the ImageButton that was pressed and since all that I know is the id of the ImageView, I was wondering how to retrieve the name of the drawable. I searched over the internet and all I found was ways of getting the id using drawable name or getting the entire file path of the drawable, so is there a way to get the name of the drawable and without the extension also, Thanks

Upvotes: 0

Views: 80

Answers (1)

Aless Otterbach
Aless Otterbach

Reputation: 161

Since an ImageButton is an ImageView you could use tagging:

ImageButton button = (ImageButton) findViewByID(R.id.buttonId)// your button
button.setTag("youDrawableName"); // your drawable name

And read it as you need it:

String drawableName = (String) button.getTag();

Upvotes: 1

Related Questions