1
I want to create a class to check the 2 fields EditText
are filled, called Validacao
. I wanted to call like:
if (Validacao(TextoA, TextoB) == true) {
executa código;
I don’t know what the class code looks like Validacao
. You have to have a builder Validacao()
? What the code would 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;
}
if(Nomedavariavel.gettext().toString().equals(" ")){ Toast.makeText(Mainactivity.this,"Please fill in the text", Toast.LENGTH_SHORT). show(); I don’t know if this was the doubt, but to make the validation if the text is not null is like this.
– Gabriell Serra