tags:

views:

141

answers:

1

Hello friends,

I have setup background image for a button as below.

// declarations globally declared...
ImageButton sampleButton;
int sampleFirstImage = 0;
int sampleSecondImage = R.drawable.imageSecond;
......................................
......................................
sampleFirstImage = R.drawable.imageFirst;
sampleButton.setImageResource(sampleImage);

In certain cases, i want to replace this image with the another second image if the first image is set. As i need to check the condition as first image set or not for button, i need to know what image is already being set for the button. So i want to GET, image set for the button? Is there any API which gets image id set for a control?

Thanks. Appreciate if you know and can explain it to me!

A: 

If you are setting the image yourself then you could consider adding a tag (setTag) whenever you set an image source.

When you get the tag later you will know which image was last set.

Prashast
Can you show a tag sample code lines adding with my code lines provided above as i want to get more to be clear?
I am done it, thank you very much.