[英]RadioButton not deselecting
Here is my code, I want to unselect a radio button when I click on it again. 这是我的代码,我想在再次单击时取消选择单选按钮。 Since I have some code that only works when none of the radiobuttons are selected. 由于我有一些代码仅在未选择任何单选按钮时才起作用。
if (TablesOn == true) {
TablesOn = false;
} else {
TablesOn = true;
}
if (jRadioButton1.isVisible()==true) {
jRadioButton1.setVisible(false);
jRadioButton2.setVisible(false);
jRadioButton3.setVisible(false);
jLabel3.setVisible(false);
jLabel4.setVisible(false);
jLabel5.setVisible(false);
} else {
jRadioButton1.setVisible(true);
jRadioButton2.setVisible(true);
jRadioButton3.setVisible(true);
jLabel3.setVisible(true);
jLabel4.setVisible(true);
jLabel5.setVisible(true);
}
To deselect a RadioButton
which is inside of RadioGroup
and be able to then select it again, firstly get your RadioGroup
: 要取消选择RadioGroup
内的RadioButton
并能够再次选择它,请首先获取RadioGroup
:
RadioGroup rg = (RadioGroup) findViewById(R.id.your_radio_group_name_in_layout);
And then do: 然后执行:
rg.check(-1);
Of course, you need some code to save last checked button number, and if it is pressed again, deselect it using the code above. 当然,您需要一些代码来保存上次选中的按钮编号,如果再次按下该按钮,请使用上面的代码取消选择它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.