I'm trying to create a class to check if the 2 EditText
fields are filled, called Validacao
. I wanted to call type:
if (Validacao(TextoA, TextoB) == true) {
executa código;
I'm not sure how to code the class Validacao
. Do I need to have a Validacao()
constructor? What would the code look like?
import android.widget.EditText;
import android.widget.Toast;
public class Validacao {
private boolean x = true;
private boolean y = true;
private boolean z = true;
private boolean a = false;
public Validacao(EditText textA, EditText textB) {
// Valida para ter todos os 2 campos preenchidos
if ((textA.getText().toString().isEmpty()) && (textB.getText().toString().isEmpty())) {
z = false;
Toast toast = Toast.makeText(this, "Informe os números." , Toast.LENGTH_SHORT);
toast.show();
} else if (textA.getText().toString().isEmpty()) {
x = false;
Toast toast = Toast.makeText(this, "Informe o primeiro número." , Toast.LENGTH_SHORT);
toast.show();
} else if (textB.getText().toString().isEmpty()) {
y = false;
Toast toast = Toast.makeText(this, "Informe o segundo número." , Toast.LENGTH_SHORT);
toast.show();
}
}
if (x && y && z)
a = true;
return a;
}