android RadioButton 设置每次显示是默认未选中

应用场景:
按钮点击后, 显示选择框 ,要求每次显示时, 里面的选择按钮默认都未选中
布局 :

     <RadioGroup
                android:id="@+id/rg_group"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content">
        <RadioButton
            android:id="@+id/rb_1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="test1" />
        <RadioButton
            android:id="@+id/rb_2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="test2" />
        <RadioButton
            android:id="@+id/rb_3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="test3" />
        <RadioButton
            android:id="@+id/rb_4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="test4" />
    </RadioGroup>

解决办法:
RadioGroup的clearCheck方法
显示选择框之前调用rg_group.clearCheck(); 这样每次显示时 选择框中的内容默认都未选中. 如果直接挨个setChecked(false)会出问题,下次点击不会变为选中状态


 

发布了76 篇原创文章 · 获赞 21 · 访问量 11万+

猜你喜欢

转载自blog.csdn.net/u010227042/article/details/104485328
今日推荐