android使第一个单选按钮始终处于选中状态
我正在开发一个测验应用程序,它由一个问题和存储在sqlite数据库中的三个选项组成,我正在使用这些选项的单选按钮。问题是,第一个单选按钮仅在第一次选中,当我从问题1中选择第二个选项并转到下一个问题时,第二个选项将保持选中状态,我希望在每个问题中都选择选项1。因此,如果我在下一个问题中选择了问题1中的第二个选项,则应选择第一个选项android使第一个单选按钮始终处于选中状态,android,sqlite,radio-button,Android,Sqlite,Radio Button,我正在开发一个测验应用程序,它由一个问题和存储在sqlite数据库中的三个选项组成,我正在使用这些选项的单选按钮。问题是,第一个单选按钮仅在第一次选中,当我从问题1中选择第二个选项并转到下一个问题时,第二个选项将保持选中状态,我希望在每个问题中都选择选项1。因此,如果我在下一个问题中选择了问题1中的第二个选项,则应选择第一个选项 my xml code: <RadioGroup android:id="@+id/radioGroup1" android:layout_width="wra
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>
我的xml代码:
我尝试使用java,但没有成功:
RadioButton FirstOption, SecondOption, ThirdOption;
while(questionID < 10)
{
FirstOption.isChecked();
}
单选按钮第一选项、第二选项、第三选项;
而(问题ID<10)
{
isChecked();
}
将执行此操作。
isChecked()
是一种测试方法,用于查看是否选中了radiobutton并返回布尔值。Mr雷达给出的答案是正确的。它不适用于while回路,但适用于if条件。谢谢
FirstOption.setChecked(true)