<分区>
我正在开发一个生成多项选择题的应用程序。当用户选择一个按钮(单选按钮)时,它会在所选答案旁边放置一个X(如果错误)或V(如果正确)的图像。我创建了包含所有按钮的 RadioGroup 并使用了 OnCheckedChanged Listener
。我跟踪并放置打印语句以确保它有效并且确实有效。但是,除了第一次用户按下之外,它根本不显示可绘制图像。
所以换句话说,用户将按下其中一个按钮,将看到反馈(V 或 X),但随后按下不同的按钮并不会看到任何东西,尽管逻辑确实有效(我在 if 中使用了 print 语句).我使用 SetCompoundDrawableWithIntrinsicBounds
并且它会正常工作。有人知道如何解决这个问题吗?
过去 8 个小时我都在为此工作,我感到非常沮丧。
监听器代码:
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
//get the index of the correct answer
int indexAnswer = Integer.parseInt(myQuestion.getAnswer()) - 1;
for (int i = 0; i < possibleAnswers.length; i++) {
//if the button at position i was pressed
if (checkedId == possibleAnswers[i].getId()) {
//if its the correct answer
if (i == indexAnswer) {
Log.i("MyAcitvity", "thats correct");
possibleAnswers[i].setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.checkmark, 0);
}
else {
Log.i("MyActivity", "thats wrong");
possibleAnswers[i].setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.wrong, 0);
}
} else {
possibleAnswers[i].setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
}
}
}
});
谢谢你们,祝你们有美好的一天。