Checkbox and Radiobutton Validation

Asked

Viewed 488 times

0

How to validate and return a message if Checkbox and Radiobutton components are not selected in an application ? JAVA

1 answer

2


Both in the CheckBox how much in the RadioButton there is a method that can be used to make this test, the isSelected() returning true if your component is selected.

This way you can use it to show your message, just make you deny this test before.

 if (!seuCheckBox.isSelected()) {
      System.out.println("checkbox não foi selecionado");
      JOptionPane.showMessageDialog(this, "Checkbox não foi Selecionado");
 }

In the android this same method is called isChecked

if (!seuCheckBox.isChecked()) {
  Toast.makeText(getActivity(), "checkbox não selecionado",
    Toast.LENGTH_LONG).show();
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.