Verification of a Checkbox

1

Hi, I have a question about a CheckBox of Acceptance of Terms of Use. I have 2 text boxes (EditText) and a CheckBox. What I need to achieve is that if the 2 text boxes are empty and the checkbox is not "checked", it will return an error message.

The point is that I already achieve this, but if I complete the text fields and the checkbox is still not marked the process is done something that should not happen since I must first accept the Terms of Use

button1.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if(saldo.getText.toString().equals("") && monto.getText.toString().equals("") && !checkBox.isChecked()) {
                       //Mostrar Error
                    } else {
                      // Hacer operacion
                    }

            });
    
asked by Megaherx 05.11.2017 в 22:44
source

1 answer

2

Your error is that you use the & & amp operator when what you should use is || , this is because you want that if you have not passed any of those 3 conditions, the operation does not occur, with your code you only get the operation not to be fulfilled as long as you do not give all 3 conditions at once.

button1.setOnClickListener(new View.OnClickListener() {
    @Override public void onClick(View view) {
        if (saldo.getText.toString().isEmpty() || monto.getText.toString().isEmpty()) {
            //Mostrar Error no has rellenado campos 
        } else if (!checkBox.isChecked()) {
            //Mostrar Error no has aceptado las condiciones de uso 
        } else {
            // Hacer operacion 
        }
    }
});
    
answered by 05.11.2017 / 23:31
source