-2

Am trying to get the ImageView drawable and use it to create an if else statement, i have tried many solutions including the one below, all are not working they always give me the wrong Toast

if(holder.likeImage.getDrawable()==context.getResources().getDrawable(R.drawable.ic_action_like)){
                Toast.makeText(context, "LIKED ALREADY", Toast.LENGTH_SHORT).show();
            }

            else if(holder.likeImage.getDrawable()!=context.getResources().getDrawable(R.drawable.ic_action_like)){
                Toast.makeText(context, "YOU HAVNT LIKED", Toast.LENGTH_SHORT).show();


            }
Pdee As-Diddy
  • 147
  • 2
  • 14
  • look at this answer here on how to compare two drawables http://stackoverflow.com/questions/9125229/comparing-two-drawables-in-android – Wilik Oct 05 '15 at 18:02
  • 3
    Don't use Drawable object equality to represent state -- the objects returned from getDrawable() are unique and can't be used for equality comparison. Store your state information some other way (ex. a boolean value on your holder). – alanv Oct 05 '15 at 18:04

1 Answers1

0

try this.

holder.likeImage.setImageResource(R.drawable.ic_action_like);
holder.likeImage.setTag(R.drawable.ic_action_like);
if(holder.likeImage.getTag().equals(R.drawable.ic_action_like)){

}else{

}
Deepak Goyal
  • 4,747
  • 2
  • 21
  • 46