Android 取消选中 RadioButtonGroup 中的所有 RadioButton
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10497921/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Uncheck all RadioButton in a RadioButtonGroup
提问by Jayson Tamayo
What I wanted to achieve is this: Right after the activity starts, I want that no RadioButton is selected/checked.
我想要实现的是:在活动开始后,我希望没有选择/选中 RadioButton。
My problem is this: When the activity starts, the first RadioButton is always selected/checked.
我的问题是:当活动开始时,第一个 RadioButton 总是被选中/选中。
I tried radioButton1.setChecked(false)
right after initialization of the radiobutton(inside onCreate), but when the activity starts, I can't manually check/select the first radiobutton. Till I select the 2nd or 3rd radio button, I can now select/check the first radio button.
我radioButton1.setChecked(false)
在单选按钮初始化后立即尝试(在 onCreate 内),但是当活动开始时,我无法手动检查/选择第一个单选按钮。在我选择第二个或第三个单选按钮之前,我现在可以选择/检查第一个单选按钮。
回答by Samir Mangroliya
RadioGroup radioGroup = (RadioGroup)findViewById(R.id.radiogroup);
radioGroup.clearCheck();
回答by ρяσ?ρ?я K
use clearCheck() for clearing all checked radiobutton when acticity is started or resumed
当活动开始或恢复时,使用 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();
}
回答by Prabh deep
use this
用这个
RadioButton spec1=findViewById(yourRadioGroup.getCheckedRadioButtonId());
if (spec1.isChecked())
{
spec1.setChecked(false);
}