Whenever I click on my ImageButton I want to compare the image of it with the drawable I have in the 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();
}
}
});
But it is not working, it does not return any of the Toasts