複数選択問題を生成するアプリケーションで作業しています。ユーザーがボタン(ラジオボタン)を選択すると、Xの画像(間違っている場合)またはV(もしそうならば)の画像が選択された回答の横に表示されます。すべてのボタンを含むRadioGroupを作成し、OnCheckedChanged Listener
を使用しました。私は、それが機能しているかどうかを確認するために、声明文をトレースして置いた。ただし、最初のユーザーのプレスを除いて、描画可能なイメージはまったく表示されません。ボタンの右に図面を配置する
つまり、ユーザーがボタンの1つを押すと、フィードバック(VまたはX)が表示されますが、別のボタンを押しても何も表示されませんが、ロジックは機能します( if)。私は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);
}
}
}
});
おかげで素晴らしい一日の人を持っています。