mardi 13 août 2019

If statement for two checkboxes are checked problem

I am trying to write a code that states that if one checkbox is checked the second one can not be checked at the same time. I have one checkbox called dayShift and another called nightShift. If I am checking nightShift and THEN dayShift the code works as I expected. But if I check dayShift first and THEN nightShift, the code does not apply.

public void days(View view) {
    CheckBox nightShift_check = (CheckBox)findViewById(R.id.nightShift);
    CheckBox dayShift_check = (CheckBox)findViewById(R.id.dayShift);
    if (nightShift_check.isChecked() && dayShift_check.isChecked())
    {
        nightShift_check.setChecked(false);
        dayShift_check.setChecked(false);
        Toast.makeText(mainApplication.this,"Error message",Toast.LENGTH_LONG).show();
    }
}

Aucun commentaire:

Enregistrer un commentaire