8

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?

Anu
  • 1,303
  • 3
  • 23
  • 38

5 Answers5

49

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.

aaronvargas
  • 12,189
  • 3
  • 52
  • 52
  • 2
    Solved my issue after 4hours of investigation in all classes..thanks – LearningPath Sep 28 '17 at 15:06
  • 1
    @mg3, glad I could help. I spent more time than I'd like to admit to on this and didn't see this solution posted anywhere else, so I figured someone else may benefit! – aaronvargas Oct 06 '17 at 21:08
  • 4
    seems to actually be the layout_height more specifically - and it doesn't need to be set to wrap_content as such - just needs to be big enough - but yes thanks I couldn't find this anywhere either !! – philthomas26 Mar 31 '18 at 21:10
  • 1
    @philthomas26 from the answer and from your comment, I got this idea it is actually related to height, it is now working,thanks – Rai_Gaurav Nov 21 '18 at 14:16
  • you are the best! – Bassem Wissa Jun 11 '19 at 10:51
  • @aaronvargas Thank you for an AWESOME answer, i also lost around 4 hours same as LearningPath, why don't google mention this type of issues properly.. – Vivek Thummar Feb 15 '23 at 11:04
7

You just need apply,

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

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

NidhiParekh
  • 71
  • 1
  • 3
3

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' 
Silwester
  • 418
  • 5
  • 12
1

I was having same issue and i was using data binding so adding below line solved my issue : app:errorEnabled="true"

Deepak Rajput
  • 731
  • 6
  • 20
0

Use Android Support Library, revision 23.4.0 (May 2016)

Fixed an issue where TextInputLayout doesn't clear error tint after setErrorEnabled(false) on API level 21 - 22 (Issue 202829)

Mansukh Ahir
  • 3,373
  • 5
  • 40
  • 66