Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android TextInputLayout is not showing error

I am using EditText with TextInputLayout. This is the code, that I am using to display error.

  private boolean validateEmail() {
    String email = inputEmail.getText().toString().trim();

    if (email.isEmpty() || !isValidEmail(email)) {
        inputLayoutEmail.setErrorEnabled(true);
        inputLayoutEmail.setError(getString(R.string.err_msg_email));
        requestFocus(inputEmail);
        return false;
    } else {
        inputLayoutEmail.setErrorEnabled(false);
    }

    return true;
}

I am calling this method in edittext's textwatcher like in this link http://www.androidhive.info/2015/09/android-material-design-floating-labels-for-edittext/

Once I entered a valid input then clear that ,it will show error message as expected,But it wont work if i enter the text again and then clear it again.ie.It is not showing any error message.

I am using compile 'com.android.support:design:23.1.0' library.

inputLayoutEmail.setErrorEnabled(true); 

is calling but error is not displaying. What might be the problem? How I can solve this?

like image 450
Anu Avatar asked Dec 17 '15 09:12

Anu


3 Answers

In your layout file, ensure you have layout_height="wrap_content" for the TextInputLayout instead of a dimension. This was causing the issue for me.

like image 194
aaronvargas Avatar answered Nov 13 '22 22:11

aaronvargas


You just need apply,

inputLayoutEmail.setErrorEnabled(false);
inputLayoutEmail.setError(null);

It worked for me. Hope it will work for you too.

like image 23
NidhiParekh Avatar answered Nov 14 '22 00:11

NidhiParekh


The example worked for me.

you use

compile 'com.android.support:design:23.1.0' 

and the right one is

compile 'com.android.support:design:23.0.1' 
like image 39
Silwester Avatar answered Nov 14 '22 00:11

Silwester