How to compare Image TextView background resource with R.drawable.bg_image switch for switch

Sorry for my bad english.

I have one TextView and it has a background image resource. But I need, when I click in this TextView, Android compares the current resource of the background image with one of R.drawable.bg_images in the transferable folder.

bg_image_1 bg_image_2

if the TextView setBackgroundImageResource is bg_image_1 and I click on it, switch the background image of the TextView to the resource gb_image_2.

as?

thanks

+4
source share
1 answer

You cannot get the resource identifier of a resource after setting this resource as a background. But you can store some kind of flag or even a resource identifier somewhere outside of your TextView or, possibly, in its tag field. In this case, you can get it and compare it with another identifier.

 Object tag = textView.getTag(); int backgroundId = R.drawable.bg_image_2; if( tag != null && ((Integer)tag).intValue() == backgroundId) { backgroundId = R.drawable.bg_image_1; } textView.setTag(backgroundId); textView.setBackgroundResource(backgroundId); 
+13
source

All Articles