Validate blank fields

-1

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

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

As above, I created a boolean variable with name isInserted to return true or false, but as the editVelmax variable is always filled it is always returning true even the editNome and editVecile in white. How do I validate these two fields too?

    
asked by anonymous 19.06.2016 / 17:35

1 answer

1

Check the values before the information persists:

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);
}
    
19.06.2016 / 18:14