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);
source share