Reputation: 3
I want to compare drawables. The two drawables are in an ImageButton and a variable which holds the other drawable to compare with.
Here is my code
option1.setImageResource(questionsLibrary.getOption1(questionID));
correctAnswer = questionsLibrary.getCorrectAnswer(questionID);
option1 is an ImageButton while correctAnswer is a variable that holds a drawable.
I want to compare them both to check if the option1 and correctAnswer has the same drawable.
Upvotes: 0
Views: 212
Reputation: 10635
Rather comparing drawable, take an advantage of tag property of a view. Set tag of option1.setTag("Answer or unique key")
. Then compare it by fetching tag value from ImageButton option1.getTag()
.
Upvotes: 1
Reputation: 695
Try this
if(option1.getDrawable().getConstantState().equal(correctAnswer.getConstantState())){
//Your code here
}
Upvotes: 0