I know there are many questions about checking if CheckBox
is selected or if TextView
is empty, but I try to do a check of both together and do not do it, what I have done is the following.
btn1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// compruebo si opc1 u opc2 está seleccionado y si openCalendario no está vacío
if (opc1.isChecked() || opc2.isChecked() || verificarCampoFecha()) {
// solamente ir si opc1 u opc2 está seleccionado y openCalendario no está vacío
Intent c4c5a = new Intent(Clase4.this, Clase5.class);
startActivity(c4c5a);
} else {
// opc1 opc2, si alguno de los dos no está seleccionado, mostrar:
Toast.makeText(Clase4.this, "Por favor, seleccione una franja horaria", Toast.LENGTH_SHORT).show();
// verificarCampoFecha, si openCalendario está vacío mostrar:
if (openCalendario.getText().toString().equals("")) {
Toast.makeText(Clase4.this, "Por favor, seleccione un día", Toast.LENGTH_SHORT).show();
}
}
}
});
// compruebo openCalendario
private boolean verificarCampoFecha() {
if (openCalendario.getText().toString().equals("")) {
return false;
}
return true;
}
The problem is that if TextView
is empty and CheckBox
unselected, it only shows the Toast
of CheckBox
and if the CheckBox
is selected, it goes to the next Activity
without taking into account if TextView
is empty or not.