如何使用无线电组取消选中多个单选按钮请提及我知道这个问题已存在于此网站上但代码无法运行应用程序崩溃使用此(radiogroup.clear)请发送正确的代码
使用此代码
Radiobutton radiobutton=null;
radiobutton=yourradiogroup.getcheckedid;
if(radiobutton.ischecked)
{
radiobutton.setchecked(false)
}
简单的解决方案,选择另一个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>