繁体   English   中英

单选按钮未取消选择

[英]RadioButton not deselecting

这是我的代码,我想在再次单击时取消选择单选按钮。 由于我有一些代码仅在未选择任何单选按钮时才起作用。

    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);
    }

要取消选择RadioGroup内的RadioButton并能够再次选择它,请首先获取RadioGroup

RadioGroup rg = (RadioGroup) findViewById(R.id.your_radio_group_name_in_layout);

然后执行:

rg.check(-1);

当然,您需要一些代码来保存上次选中的按钮编号,如果再次按下该按钮,请使用上面的代码取消选择它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM