0
我正在研究android中的测验应用程序。我需要用单选按钮显示问题及其选项。当下一个按钮被点击下一个问题时,它的选项将被显示。我能够显示问题和选项,但我遇到了一个问题。如何在android中单击下一个按钮时删除单选按钮?
第一次第一个问题及其选项显示正常。当下一个按钮被点击后,下一个问题正在显示,但是对于选项,第一个问题选项和第二个问题选项都会显示单选按钮。再次点击下一个按钮时,同时显示第一个,第二个选项的第三个问题。单击下一个按钮时,如何删除上一个问题的单选按钮。
我的代码:
main.xml中
<ScrollView
android:id="@+id/scrl"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@+id/widgetnotes"
android:layout_margin="6dp"
android:background="#FFFFFF"
android:scrollbars="none" >
<RelativeLayout
android:id="@+id/rel"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/tv_question"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#000000" />
<LinearLayout
android:id="@+id/chklnlayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@+id/tv_question"
android:orientation="vertical" >
</LinearLayout>
</RelativeLayout>
</ScrollView>
Page.java
{
------
//first question----
optionslayout = (LinearLayout) findViewById(R.id.chklnlayout);
tv.setText(question);
tv.setTextColor(Color.parseColor("#000000"));
RadioGroup radiogroup = (RadioGroup) new RadioGroup(Page.this);
optionslayout.addView(radiogroup);
for (int k = 0; k < arr.length; k++) {
RadioButton newRadioButton = new RadioButton(Page.this);
newRadioButton.setText(arr2.get(k));
newRadioButton.setTextColor(Color.parseColor("#000000"));
radiogroup.addView(newRadioButton);
}
//next click--
public void next(View v)
{
if (i < array.length - 1) {
i++;
optionslayout = (LinearLayout) findViewById(R.id.chklnlayout);
tv.setText(question);
tv.setTextColor(Color.parseColor("#000000"));
RadioGroup radiogroup = (RadioGroup) new RadioGroup(Page.this);
optionslayout.addView(radiogroup);
for (int p = 0; p < nextarr.length; p++) {
RadioButton newRadioButton = new RadioButton(Page.this);
newRadioButton.setText(arr6.get(p));
newRadioButton.setTextColor(Color.parseColor("#000000"));
radiogroup.addView(newRadioButton);
}
}
}
我试图把optionslayout.removeAllViews();
在明年的点击动作,但是当我把它不会显示下一题的选项。请帮我解决这个问题。
嗨,我还加optionslayout.removeView(RadioGroup中); – user1448108