Calvin Jones
Calvin Jones

Reputation: 367

check condition of radio button

I have a radio button that turns a string into binary format in my editText field. 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.

Upvotes: 1

Views: 356

Answers (1)

No Idea For Name
No Idea For Name

Reputation: 11607

you should replace the radio button in a real button and register the 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.

Upvotes: 1

Related Questions