Moayed I. Alayseh Moayed I. Alayseh - 1 month ago 12
Android Question

how to hide set error into edit text Android

I have two

EditText
and i set error when the edit text is empty , but the problem is when the
EditText
take value , the error still show , like this:

enter image description here

This is my code :

String username= edit_text_username.getText().toString();
String password = edit_text_password.getText().toString();
if (username.equals("")) {
progressDialogLogin.dismiss();
layoutUsername.setError(" required!");
Layoutpassword.requestFocus();
}
else if (password.equals("")) {
progressDialogLogin.dismiss();
Layoutpassword.setError(" required!");
}

else {


any idea ?

Answer

Try this,

edtUserName.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                if (edtUserName.getText().toString().trim().length() > 0) {
                    usernameLayout.setError(null);

                }
            }
        });

Hope this will help you