Reputation: 1156
How should I get current image resource of an imageButton? I need something like this:
imageButton.getImageResource();
Thanks a lot
Upvotes: 18
Views: 38298
Reputation: 49
You can use imageButton.getDrawable()
to get the drawable of the ImageButton object and then use setImageDrawable()
instead of setImageResource()
.
Upvotes: 4
Reputation: 1020
Use this
imageButton.setImageResource(R.drawable.your_resource);
imageButton.setTag(R.drawable.your_resource);
Integer resource = (Integer) imageButton.getTag();
if(resource == R.drawable.your_resource){
// do something
}else {
}
Upvotes: 0
Reputation: 9207
I think you can't, current API doesn't allow this. But if you really need this, you can do something like this:
imageButton.setImageResource(R.drawable.your_resource);
imageButton.setTag(R.drawable.your_resource);
//
// somewhere later...
//
Integer resource = (Integer)imageButton.getTag();
Upvotes: 33