我想要实现的是:在活动开始后,我希望没有选择/选中任何RadioButton。
我的问题是:当活动开始时,第一个RadioButton总是被选中/选中。
我在初始化单选按钮(在onCreate中)之后立即尝试了radioButton1.setChecked(false)
,但是当活动开始时,我无法手动选中/选择第一个单选按钮。在我选择第二个或第三个单选按钮之前,我现在可以选择/选中第一个单选按钮。
发布于 2012-05-08 19:44:29
RadioGroup radioGroup = (RadioGroup)findViewById(R.id.radiogroup);
radioGroup.clearCheck();
发布于 2012-05-08 19:50:27
当活动开始或恢复时,使用clearCheck()清除所有选中的单选按钮
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
RadioGroup rg=(RadioGroup)findViewById(R.id.RG);
rg.clearCheck();
}
@Override
protected void onResume() {
RadioGroup rg=(RadioGroup)findViewById(R.id.RG);
rg.clearCheck();
super.onResume();
}
发布于 2019-01-16 21:24:21
使用这个
RadioButton spec1=findViewById(yourRadioGroup.getCheckedRadioButtonId());
if (spec1.isChecked())
{
spec1.setChecked(false);
}
https://stackoverflow.com/questions/10497921
复制相似问题