Android TextInputLayout is not showing error
Asked Answered
S

5

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?

Soaring answered 17/12, 2015 at 9:46 Comment(1)
Change requestFocus(inputEmail); -> inputEmail.requestFocus();Oleary
S
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' 
Scrubland answered 17/12, 2015 at 10:17 Comment(5)
it is working in first time.Second time onwards it is not showing error.but getting focus.Soaring
ok. I got it - you use compile 'com.android.support:design:23.1.0' and the right one is compile 'com.android.support:design:23.0.1'Scrubland
thanks..It works with com.android.support:design:23.0.1Soaring
Can you please add this in your answer.So that I can accept your answerSoaring
what about if my compile sdk version will 24 ?Linder
P
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.

Paz answered 29/6, 2017 at 17:8 Comment(6)
Solved my issue after 4hours of investigation in all classes..thanksKeratin
@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!Paz
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 !!Retrorocket
@Retrorocket from the answer and from your comment, I got this idea it is actually related to height, it is now working,thanksBioplasm
you are the best!Murvyn
@Paz 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..Gravid
S
7

You just need apply,

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

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

Scanlon answered 20/5, 2016 at 13:22 Comment(0)
S
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' 
Scrubland answered 17/12, 2015 at 10:17 Comment(5)
it is working in first time.Second time onwards it is not showing error.but getting focus.Soaring
ok. I got it - you use compile 'com.android.support:design:23.1.0' and the right one is compile 'com.android.support:design:23.0.1'Scrubland
thanks..It works with com.android.support:design:23.0.1Soaring
Can you please add this in your answer.So that I can accept your answerSoaring
what about if my compile sdk version will 24 ?Linder
A
1

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

Atharvaveda answered 30/12, 2019 at 9:58 Comment(0)
S
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)

Saraband answered 16/5, 2016 at 4:35 Comment(1)
This issue does not seem to be fixed in 23.4.0.Personal

© 2022 - 2024 — McMap. All rights reserved.