Android 我有4个单选按钮。我希望每次都选中上次选中的单选按钮

Android 我有4个单选按钮。我希望每次都选中上次选中的单选按钮,android,Android,我有4个单选按钮。我希望每次都选中上次选中的单选按钮。直到我不改变它。(当我重新打开我的应用程序时,发现它已被选中)您可以使用android:checked=“true”保留默认情况下要选中的任何单选按钮。在这种情况下,默认情况下会选中第二个按钮 <RadioGroup xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_he

我有4个单选按钮。我希望每次都选中上次选中的单选按钮。直到我不改变它。(当我重新打开我的应用程序时,发现它已被选中)

您可以使用
android:checked=“true”
保留默认情况下要选中的任何单选按钮。在这种情况下,默认情况下会选中第二个按钮

<RadioGroup xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RadioButton android:id="@+id/radio_pirates"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/pirates"
    android:onClick="onRadioButtonClicked"/>
<RadioButton android:id="@+id/radio_ninjas"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/ninjas"
    android:checked="true"
    android:onClick="onRadioButtonClicked"/>


请显示HTML…不要让我们猜测与问题共享您的代码欢迎来到StackOverflow社区。如果您对一些非常具体的问题有疑问,您应该包括您的代码。如果您还没有尝试实现某些功能,我强烈建议您进一步搜索您的问题。你想做的事情似乎很平常。(提示:搜索
SharedReference
)在
共享首选项中保存该按钮状态
,然后在打开应用程序时,根据
共享首选项保存状态设置其状态
简单。
android:checked=“true”
将此行添加到最后一个(第四个)单选按钮。每次选中最后一个时,它都会使。如果任何其他单选按钮有此行,请将其从其他单选按钮中删除。我是在安卓环境下回答的,因为您添加了安卓标签。