現在、私は自分のクイズのアプリケーションを開発し、2日間問題を検討しています。私のクイズには、多肢選択肢と単一選択肢の2種類の質問があります。だから私はCheckBoxesを使用している複数の選択肢の質問のために、単一の選択肢バリアントにはRadioButtonsがあります。チェックされたRadioButtonsの奇妙な動作
ユーザが質問に回答して次の質問に進むと、その結果が自分のSQLiteデータベースに保存されます。彼が前の質問に戻ると、私は保存された結果を表示しています。
ここに例があります: イメージ1には、左側の5つのチェックボックスがあります。これらは正解です。右側のチェックボックスは、ユーザーのチェック済みの回答です。これは質問に答えたときに表示される画面です。「次へ」ボタンをクリックして答えた質問に戻ります。 CheckBoxesの場合、正常に動作し、正しく動作します。画像2オン
あなたは、単一の選択肢の質問と同じユースケースが、この時間を参照してください。あなたが見ることができるように、右側にはRadioButtonがチェックされていません。しかし、実際には私は中間の答えをチェックし、結果はまた私のデータベースに保存されます。私は自分のアプリケーションをデバッグする場合
はそれが正しいセクションにもジャンプして右のRadioButtonをチェックします。しかし、それはチェックされたとして表示されず、私はここでエラーを見つけることができません。
String resultString = userResultCursor.getString(userResultCursor.getColumnIndexOrThrow(MyDatabase.ResultColumns.RESULT));
String resultArray[] = convertStringToArray(resultString);
List<String> resultList = Arrays.asList(resultArray);
for (String id : resultList) {
if (question.getQuestiontype() == 1) {
for (CheckBox cb : answerCheckBoxes) {
if (cb.getId() == Integer.parseInt(id)) {
cb.setChecked(true);
}
cb.setEnabled(false);
}
}
if (question.getQuestiontype() == 2) {
for (RadioButton rb : answerRadioButtons) {
if (rb.getId() == Integer.parseInt(id)) {
rb.setChecked(true);
}
rb.setEnabled(false);
}
}
何が問題なのですか? Saurabh Padwekarソリューションでは、それが確認されたRadioButtonが表示されます。ここでは
は、ラジオボタン
<LinearLayout
android:id="@+id/layout_singlechoice_answers"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:orientation="vertical">
<RadioGroup
android:id="@+id/myRadioGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RadioButton
android:id="@+id/rb_answer1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<RadioButton
android:id="@+id/rb_answer2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<RadioButton
android:id="@+id/rb_answer3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<RadioButton
android:id="@+id/rb_answer4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<RadioButton
android:id="@+id/rb_answer5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RadioGroup>
</LinearLayout>
EDITのレイアウトです。しかし、それをテストした後、私は少し気付きました。時々、私がRadioButtonをチェックしたい場合、それはチェックされません。主に動作しますが、しばらくしては動作しません。
単一選択問題のレイアウトxmlを投稿してください – 0X0nosugar
2つのグループが定義されていますか? 1つは左の列、もう1つは右の列ですか? –
@David Wasser私は右の列のRadioGroupを宣言しました –