im coding the onClick method for a ImageButton and I have to compare the image in the button with another one from my resources folder to do some things. This is the code I wrote, where I put some log messages:
public void onClick(View v){
Log.e(LOGTAG, "bolarojo: "+getResources().getDrawable(R.drawable.bolarojo).getConstantState().toString());
Log.e(LOGTAG, "bolaclic: "+v.getBackground().getConstantState().toString());
if(v.getBackground().getConstantState().equals(getResources().getDrawable(R.drawable.bolarojo).getConstantState())){
Log.e(LOGTAG, "buh");
And it shows: bolarojo: android.graphics.drawable.BitmapDrawable$BitmapState@4106ac08 bolaclic: android.graphics.drawable.StateListDrawable$StateListState@41070780 Since v is holding R.drawable.bolarojo shouldn't the log messages be the same? Anyways I don't undestand why it doesn't show "buh".