簡體   English   中英

我有 4 個單選按鈕。 我希望每次都選擇我上次選擇的單選按鈕

[英]I have 4 radio buttons. I want that my last selected radio button get selected everytime

我有 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"/>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM