i am trying to compare the view background to the drawable but its not working for me.
View v1 = options.findViewById(i);
v1.findViewById(R.drawable.back);
Drawable d = v1.getBackground();
if(d.getConstantState() == getResources().getDrawable(R.drawable.correct_ans_back)){
v1.setBackgroundResource(R.drawable.a);
}else{
view.setBackgroundResource(R.drawable.b);
}
how to check i am getting an error here.
incompatible operand types Drawable.Constant State and Drawable
1) Replace
with
This will solve the
incompatible operand types Drawable.Constant State and Drawable
error.2) If you are not able to compare two bitmaps, then you can use the below method.
3) OR , you can assign two different
TAG
to the background images and compare theTAG
only instead of comparing drawable directly. You can also set background'sTAG
as drawable's id and compare it as described below,