Android:How to get back image set for a button programmatically?
I have setup background image for a button as below.
// declarations globally declared...
ImageButton sampleButton;
int sampleFirstImage = 0;
int sampleSecondImage = R.drawable.imageSecond;
......................................
.......................开发者_如何学JAVA...............
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!
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.
精彩评论