You have written your code in onClick
event. This will call when you click on EditText
. But this is something like you are checking it before entering.
So what my suggestion is, you should use focus changed
. When any view get focus, you are setting no error
and when focus changed, you check whether there is valid input or not like below.
firstName.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View arg0, boolean arg1) {
firstName.setError(null);
if (firstName.getText().toString().trim().equalsIgnoreCase("")) {
firstName.setError("Enter FirstName");
}
}
});