Hello, I have a set of 8 checkBoxs. Does anyone know how I can check if at least 1 of them has been selected? Thank you
Hello, I have a set of 8 checkBoxs. Does anyone know how I can check if at least 1 of them has been selected? Thank you
If you want to test one-by-one:
boolean algumSelecionado = jcbx1.isSelected() || jcbx2.isSelected() || jcbx3.isSelected() || jcbx4.isSelected()
|| jcbx5.isSelected() || jcbx6.isSelected() || jcbx7.isSelected() || jcbx8.isSelected();
Or a more dynamic solution if JCheckBox is inside a JPanel:
boolean algumSelecionado = false;
for (Component c : jpnl.getComponents()) {
if (c instanceof JCheckBox && ((JCheckBox) c).isSelected()) {
algumSelecionado = true;
break;
}
}
CheckBox checkBox1 = (CheckBox) findViewById(R.id.checkBox1);
checkBox1.isChecked();