0

I am developing a quiz application which consists of a question and three options stored in sqlite database and I am using radio buttons for these options. the problem is the first radio button will be selected first time only and when I select for example the second option from question 1 and I go to the next question the second option will remain selected and I want the option 1 to be selected in every question. so if I selected the second option from question 1 in the next question the first option should be selected.

my xml code:

<RadioGroup
android:id="@+id/radioGroup1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView1"
android:layout_centerHorizontal="true"
>

<RadioButton
android:id="@+id/radio0"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:checked="true"
android:text="RadioButton" />

<RadioButton
android:id="@+id/radio1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="RadioButton" />

<RadioButton
android:id="@+id/radio2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="RadioButton" />
</RadioGroup>

and I tried using java but it didn't work:

RadioButton FirstOption, SecondOption, ThirdOption;   

while(questionID < 10) 
{
FirstOption.isChecked();    
}
1
  • 1
    isChecked() is a test method to see if the radiobutton is checked and returns a boolean. The answer from Mr Radar is correct way to do it.
    – Squonk
    May 14, 2014 at 12:31

1 Answer 1

2
FirstOption.setChecked(true)

will do the trick.

1
  • it didn't work with while loop but it did work with if condition. thanks May 14, 2014 at 12:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.