0

我正在开发 android 中的测验应用程序。我需要使用单选按钮显示问题及其选项。单击下一个按钮时,将显示下一个问题并显示其选项。我能够显示问题和选项,但我遇到了一个问题。

第一次第一个问题及其选项显示正常。单击下一个按钮时,将显示下一个问题,但对于选项,将显示第一个问题选项和带有单选按钮的第二个问题选项。再次单击下一个按钮时,第三个问题也会显示第一个、第二个选项。单击下一个按钮时,如何删除上一个问题的单选按钮。

我的代码:

主要的.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();进行下一个单击操作,但是当我保持它不显示下一个问题的选项时。请帮我解决这个问题。

4

1 回答 1

1

试试这个:

将无线电组设置为,

radioGroup.clearCheck();

和单选按钮为:

.setChecked(false);
于 2013-04-19T07:09:09.303 回答