10 の多肢選択問題のリストがあり、各問題には「RadioGroup」があります。しかし、質問のオプションを選択するたびに、他の質問のオプションの一部が自動的に選択されます。
質問 1 のオプションを選択したとします。次に、質問番号 5、9 が同じオプションで自動的に選択されます。
問題 2 のオプションを選択すると、問題番号 6、10 が同じオプションで自動的に選択されます。
これは起こるべきではありません。オプションを選択するときはいつでも、その RadioGroup のそのオプションだけをチェックする必要があります。これを修正するのを手伝ってください。
モバイルベースのテストを開発しています。ユーザーがユーザー名とパスワードを入力すると、サーバーはそれを認証します。許可されたユーザーに対しては、問題用紙を JSONObject として返します。各試験には、次のように、exam_id と 10 個の多肢選択問題のリストがあり、各問題には 1 つの一意の「id」、「question」、および 4 つのオプション「A」、「B」、「C」、および「D」があります。「質問」オブジェクトは JSONArray です。
{
"exam_id": 0,
"questions": [
{
"A": "A",
"C": "c",
"B": "b",
"D": "d",
"question": "A",
"id": 1,
},
{
"A": "a",
"C": "c",
"B": "B",
"D": "d",
"question": "B",
"id": 2,
},
....
....
]
}
ListAdapter を使用して、これらの値をリストに割り当てようとしています。これがそのためのアクティビティです...
public class MBTExam extends ListActivity {
JSONObject result;
String exam_id;
JSONArray question_list_json;
ArrayList<String> question_list;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.test);
Bundle extras = getIntent().getExtras();
try {
result = new JSONObject(extras.getString("result"));
exam_id = result.getString("exam_id");
question_list_json = result.getJSONArray("questions");
ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();
for (int i = 1; i <= question_list_json.length() ; i++) {
HashMap<String, String> map = new HashMap<String, String>();
JSONObject e = question_list_json.getJSONObject(i-1);
map.put("id", new Integer(i).toString());
map.put("question", e.getString("question"));
map.put("A", e.getString("A"));
map.put("B", e.getString("B"));
map.put("C", e.getString("C"));
map.put("D", e.getString("D"));
mylist.add(map);
}
ListAdapter adapter = new SimpleAdapter(this,
mylist,
R.layout.mbt_test,
new String[] { "id", "question", "A", "B", "C", "D" },
new int[] { R.id.question_no, R.id.question, R.id.A, R.id.B, R.id.C, R.id.D });
setListAdapter(adapter);
} catch (JSONException e) {
Log.e("log_tag", "Error parsing data " + e.toString());
}
}
}
各質問の行レイアウトは次のとおりです
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="top" >
<TextView
android:id="@+id/question_no"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignWithParentIfMissing="true" />
<TextView
android:id="@+id/white_space"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/question_no"
android:text="@string/white_space" />
<TextView
android:id="@+id/question"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/white_space" />
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/question" >
<RadioButton
android:id="@+id/A"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<RadioButton
android:id="@+id/B"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<RadioButton
android:id="@+id/C"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<RadioButton
android:id="@+id/D"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RadioGroup>
</RelativeLayout>
これが「MBTExam」のレイアウトです
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="top" >
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/android:list">
</ListView>
<Button
android:id="@+id/submit"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Submit"/>
</LinearLayout>
また、質問とともに、論文の最後に送信ボタンを取得する必要があります。レイアウト コードに必要な変更を提案してください。
ここに私の完全なソースコードがあります
前もって感謝します。