我有一个包含 10 个多项选择题的列表,每个问题都有一个“RadioGroup”。但是,当我为一个问题选择一个选项时,其他问题的一些选项会自动选择。
假设我为问题选择了一个选项 - 1。然后问题编号 - 5、9 会自动选择相同的选项。
当我为问题 - 2 选择一个选项时,问题编号 - 6、10 会自动选择相同的选项。
这不应该发生。当我选择一个选项时,应该只检查该 RadioGroup 中的那个选项。请帮我解决这个问题。
我正在开发基于移动设备的测试。当用户输入他的用户名和密码时,服务器将对其进行身份验证。对于授权用户,它将以 JSONObject 形式返回试卷。每个考试将有一个exam_id 和一个包含10 个多项选择题的列表,而每个问题都有一个唯一的“id”、“question”和四个选项“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>
此外,除了问题,我还必须在论文末尾获得一个提交按钮。请建议我对布局代码进行必要的更改。
这是我的完整源代码
提前致谢。