开发者

Android:How to get back image set for a button programmatically?

开发者 https://www.devze.com 2022-12-24 13:32 出处:网络
I have setup background image for a button as below. // declarations globally declared... ImageButton sampleButton;

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号