複数の選択肢の質問を生成するアプリに取り組んでいます。ユーザーがボタン (ラジオ ボタン) を選択すると、選択した回答の横にX (間違っている場合) または V (正しい場合) の画像が表示されます。すべてのボタンを含む RadioGroup を作成し、 を使用しOnCheckedChanged Listener
ました。printステートメントをトレースして配置し、機能することを確認しました。ただし、ユーザーが最初に押す場合を除いて、描画可能な画像はまったく表示されません。
つまり、ユーザーはボタンの 1 つを押すと、フィードバック (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);
}
}
}
});
素晴らしい一日をありがとう。