0

I have an imageButton :

img = (ImageButton)findViewById(R.id.image3);

I wanted to check if this img has a specific image , if yes then it changes to another image.

How can I get and store the image resource and later can be used to compare with the current image source?

this is da code :

ImageButton img = (ImageButton)findViewById(R.id.image3);
int resource = img.getResources().getInteger(android.R.drawable.btn_star_big_off);

if(resource==android.R.drawable.btn_star_big_off)
{
    img.setImageResource(android.R.drawable.btn_star_big_on);
}

Doesn't seem to be working Any other way?

Edward Falk
  • 9,991
  • 11
  • 77
  • 112
Karate_Dog
  • 1,265
  • 5
  • 20
  • 37

1 Answers1

2
myImageButton.setTag(R.drawable.currentImage);    //set this along when you set your image source

int drawableId = (Integer)myImageButton.getTag(); //get the resource
Basim Sherif
  • 5,384
  • 7
  • 48
  • 90