SageCoder SageCoder - 5 months ago 9
Android Question

Get the name of the image resource used in image button

I'm new to Android programming and I want to know that how can I get the name of the image resource that is currently set on the image button.
eg : b1.setImageResource(R.drawable.img);
//where b1 is the image button and img is the name of the png file present in res/drawable.

Now I would like to know how would I get the name of the image file i.e "img".
Thanks in advance.

Answer

You can use setTag() and getTag() this way you can store any data you want.

imageView.setTag("imageNameHere");
String imageName = (String) imageView.getTag();

Let me know! ;)