How to compare Drawables?

Asked

Viewed 216 times

3

Guys, here’s the thing... I wonder how I see if the file that this set in the Imagebutton is equal to such drawable.

To make it easier I’d like to do something like this:

final ImageButton imgBt = (ImageButton) findViewById(R.id.ImageSelect);

if(imgBt.getDrawable() == R.drawable.circle_blue) {
    //Executar Codigo
}

But then it’s not right... someone could help me?

  • 1

    Jeiferson, I don’t think that’s possible, maybe there’s a way. But by making a subclass of ImageButton for example that you know the id of Drawable would be fine, take a look at that answer to see if it helps you find the way: http://answall.com/questions/38283/como-pega-id-de-um-imageview-no-android/38311#38311

1 answer

0

Jeiferson, a possible workaround would be to set a tag on the button, where the tag would be the drawable id.

Example:

meuLindoBotao.setTag(R.drawable.imagemAtual);    
int imagemDoMeuLindoBotao = (Integer) meuLindoBotao.getTag(); //vai retornar o id do drawable atual

Done this, you would only need to compare the id to whatever you want!

I hope I’ve helped!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.