0
我在Android设备上写了一个测验应用程序,其中有一些问题。每个问题都有一个收音机组和至少4个单选按钮的应答选项。在收音机组中选择一个单选按钮会导致在不同的收音机组中选择一些单选按钮
作为测验活动的测验页,我用我列表视图。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/content_question_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="ir.testravanshenasi.segalclinic.test.QuestionListActivity"
tools:showIn="@layout/activity_question_list">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true">
<TextView
android:text="test questions"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textView13"
android:layout_marginBottom="10dp"
android:textAlignment="center"
android:textSize="18sp" />
<View
android:layout_width="match_parent"
android:layout_height="3dp"
android:background="@android:color/darker_gray"
android:layout_alignParentTop="true" />
<ListView
android:layout_width="match_parent"
android:id="@+id/activity_question_list_list"
android:layout_height="430dp">
</ListView>
<View
android:layout_width="match_parent"
android:layout_height="3dp"
android:background="@android:color/darker_gray"
android:layout_alignParentTop="true" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="5dp"
android:paddingRight="5dp">
<Button
android:text="cancel"
android:layout_width="wrap_content"
android:id="@+id/activity_question_list_cancel"
android:layout_weight="1"
android:textSize="18sp"
android:layout_height="40dp"
android:onClick="onCancelBtnClick" />
<Button
android:text="end"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:id="@+id/activity_question_list_complete"
android:layout_weight="1"
android:textSize="18sp"
android:background="@android:color/holo_green_dark"
android:onClick="onCompleteBtnClick" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
我为每个问题行做了布局。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="10dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="10dp">
<TextView
android:text="TextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/question_id"
android:visibility="gone" />
<TextView
android:text="TextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/question_text" />
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/question_options">
<RadioButton
android:text="RadioButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/question_option_1"
android:layout_weight="1" />
<RadioButton
android:text="RadioButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/question_option_2"
android:layout_weight="1" />
<RadioButton
android:text="RadioButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/question_option_3"
android:layout_weight="1" />
<RadioButton
android:text="RadioButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/question_option_4"
android:layout_weight="1" />
<RadioButton
android:text="RadioButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/question_option_5"
android:layout_weight="1"
android:visibility="gone" />
</RadioGroup>
</LinearLayout>
我添加问题作为SimpleAdapter列表视图。
String[] from = {"qid" , "question" , "op1","op2" , "op3" , "op4"};
int[] to = { R.id.question_id , R.id.question_text , R.id.question_option_1 ,R.id.question_option_2 , R.id.question_option_3 , R.id.question_option_4 };
questionsList = parse(jsonArray);
SimpleAdapter rlt = new SimpleAdapter(
getBaseContext() , questionsList , R.layout.question ,from , to);
lv.setAdapter(rlt);
的问题是,当我选择(例如)在一个问题的第一个答案选项,在其他一些问题,选择了第一个选项了。
我在Genymotion测试我的应用程序。
谢谢。
显示正在implementig –
代码中没有人能够帮助你,直到你告诉他们你完成了。 –