Reputation: 487
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.
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.
My code:
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);
}
}
}
I tried putting optionslayout.removeAllViews();
in next click action but when I kept that it is not displaying options of next question. Please help me with this issue.
Upvotes: 0
Views: 559
Reputation: 835
just try this:
set Radio Group as,
radioGroup.clearCheck();
and Radiobutton as:
.setChecked(false);
Upvotes: 1