How to remove the radio buttons when next button is clicked in android?
<p>I am working on quiz application in android. I need to display a questions and its options with radio buttons. When next button is clicked next question and its options will be displayed. I am able to display the questions and options but I am getting one issue. </p>

<p>First time first question and its options are displaying fine. When next button is clicked next question is displaying but for options both first question options and second question options with radio buttons are displaying. Again when next button is clicked third question with 1st,2nd options also displaying. How can I remove the radio buttons of previous question when next button is clicked.</p>

<p>My code:</p>

<p>main.xml</p>

<pre><code>  &lt;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" &gt;

        &lt;RelativeLayout
            android:id="@+id/rel"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" &gt;

            &lt;TextView
                android:id="@+id/tv_question"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:textColor="#000000" /&gt;

            &lt;LinearLayout
                android:id="@+id/chklnlayout"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_below="@+id/tv_question"
                android:orientation="vertical" &gt;
            &lt;/LinearLayout&gt;
        &lt;/RelativeLayout&gt;
    &lt;/ScrollView&gt;

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 &lt; 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 &lt; 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 &lt; nextarr.length; p++) {
                RadioButton newRadioButton = new RadioButton(Page.this);

                newRadioButton.setText(arr6.get(p));
                newRadioButton.setTextColor(Color.parseColor("#000000"));



                radiogroup.addView(newRadioButton);

            }


}

}
</code></pre>

<p>I tried putting <code>optionslayout.removeAllViews();</code> in next click action but when I kept that it is not displaying options of next question. Please help me with this issue.</p>
