如何使用无线电组取消选中单选按钮

问题描述 投票:0回答:2

如何使用无线电组取消选中多个单选按钮请提及我知道这个问题已存在于此网站上但代码无法运行应用程序崩溃使用此(radiogroup.clear)请发送正确的代码

android
2个回答
0
投票

使用此代码

Radiobutton radiobutton=null;

radiobutton=yourradiogroup.getcheckedid;
if(radiobutton.ischecked)
{
radiobutton.setchecked(false)
}

1
投票

简单的解决方案,选择另一个RadioButton将清除以前的选择。

<RadioGroup
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:checkedButton="@+id/checkedInitialbtn"
     android:orientation="horizontal">

    <RadioButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="50dp"
        android:text="Option1" />

    <RadioButton
        android:id="@+id/checkedInitialbtn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Option2" />
</RadioGroup>
© www.soinside.com 2019 - 2024. All rights reserved.