简体   繁体   English

检查单选按钮的状态

[英]check condition of radio button

I have a radio button that turns a string into binary format in my editText field. 我有一个单选按钮,可在我的editText字段中将字符串转换为二进制格式。 Once the user enters a number, that number should be converted into binary. 用户输入数字后,该数字应转换为二进制。 I've checked if the binary radio button is pressed. 我检查了二进制单选按钮是否被按下。 The first time the user enters a value it works great and is converted to binary. 用户第一次输入值时,它会很好用,并转换为二进制。 But once they enter a different number it stays in decimal form. 但是,一旦他们输入了不同的数字,它将保留为十进制形式。

you should replace the radio button in a real button and register the actionListener : 您应该将单选按钮替换为真实按钮并注册actionListener

    rb.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
           if(rb.getChecked())
           {
                String toBinray=this.editText.getText().toString();
                String bin=Integer.toBinaryString(Integer.valueOf(toBinray));
                this.displayText.setText(bin);
           }
           else
           {
                // Convert the binary value to integer
           }
        }
    });

if you must stay with radio button register it's actionListener , but you also must check the input is in binary form if the radio is checked. 如果必须使用单选按钮注册,则必须使用actionListener ,但是如果选中了单选,则还必须检查输入为二进制形式。

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

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