質問

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();    
}
役に立ちましたか?

解決

FirstOption.setChecked(true)

will do the trick.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top