0
I have to check the consistency of some fields in my application, but I can’t get the process to stop so that the user enters the correct information. The way I put it, the error message is displayed but the processing continues, see the commands below. What should I do?
InputMethodManager imm = (InputMethodManager) getSystemService(Activity.INPUT_METHOD_SERVICE);
if (rendim.getText().toString().isEmpty())
{
rendim.setError("Preencha o salário");
rendim.requestFocus();
imm.showSoftInput(rendim, InputMethodManager.SHOW_IMPLICIT);
}
else
{
objVal_or = new Val_or();
rendimento = objVal_or.va_lor(rendim.getText().toString());
if (rendimento <= 0)
{
rendim.setError("Salário zerado");
rendim.requestFocus();
imm.showSoftInput(rendim, InputMethodManager.SHOW_IMPLICIT);
}
}
In what situation does the process continue, when should it stop? I do not understand what is really happening. If the field is not filled
rendim
empty and the messagePreencha o salário
If therendim
is completed and is<=0
appearsSalário zerado
– Alan Vieira Rezende
Solved, missing the Return command at the end of the IF block, I switched to a simpler form: if (rendim.gettext().toString().isEmpty()) { rendim.setError("Fill in salary"); rendim.requestFocus(); Return; } Else {
 objVal_or = new Val_or();
 rendimento = objVal_or.va_lor(rendim.getText().toString());
 if (rendimento <= 0)
 {
 rendim.setError("Salário zerado");
 rendim.requestFocus();
 Return; } }
– Daniel Tibúrcio