Validate blank fields

Asked

Viewed 172 times

-1

I have a form with 3 fields to be filled and stored in bank. One of the fields is filled by the system the rest by the user.

boolean isInserted = myDb.insertData(editNome.getText().toString(),
                                editVeiculo.getText().toString(),
                                editVelmax);

As above, I created a Boolean variable named isInserted to return true or false, but as the variable editVelmax is always filled it is always returning true even the fields editName and editVeiculo blank. How do I validate these two fields as well?

  • Was any of the answer helpful? Don’t forget to choose one and mark it so it can be used if someone has a similar question!

1 answer

1

Check the values before persisting the information:

boolean isInserted = false;
String nome = editNome.getText();
String veiculo = editVeiculo.getText();

if(nome != null && veiculo != null && !nome.trim().isEmpty() && !veiculo.trim().isEmpty()){
     isInserted = myDb.insertData(nome, veiculo, editVelmax);
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.