0
Every time I click on my Imagebutton I want to compare his image with the drawable I have in Resources.
imag.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ImageButton photo = (ImageButton)view;
Drawable imagem= photo.getBackground();
Drawable cartOff = getContext().getResources().getDrawable(R.drawable.cart_off);
Drawable cart = getContext().getResources().getDrawable(R.drawable.cart);
if(imagem.equals(cart))
{
Toast.makeText(getContext(), " certo", Toast.LENGTH_SHORT).show();
}
if(imagem.equals(cartOff))
{
Toast.makeText(getContext(), " errado", Toast.LENGTH_SHORT).show();
}
}
});
Only it’s not working, not returning any of the Toasts