3

I use TextInputLayout for EditText, and if I call TextInputLayout.setError() method I get error view - it's ok.

<android.support.design.widget.TextInputLayout
        android:id="@+id/text_i_l"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <EditText
            android:id="@+id/edit_text"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="text"
            android:singleLine="true" />

    </android.support.design.widget.TextInputLayout>

But when I start input data to EditText this error doesn't hide. How can I close this error?

Artem
  • 4,569
  • 12
  • 44
  • 86
  • [http://stackoverflow.com/questions/31808157/textinputlayout-error-after-enter-value-into-edittext](http://stackoverflow.com/questions/31808157/textinputlayout-error-after-enter-value-into-edittext) – M D Apr 20 '16 at 11:09

1 Answers1

9

Simple, to detect change in your TextInputLayout, add a TextWatcher:

TextInputLayout.addTextChangedListener(new TextWatcher() {
        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {

            TextInputLayout.setErrorEnabled(false) // disable error
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void afterTextChanged(Editable s) {
        }
    });
Joel Min
  • 3,387
  • 3
  • 19
  • 38
  • I use `com.google.android.material.textfield.TextInputLayout` and option `addTextChangedListener()` available for `TextInputEditText` **not in TextInputLayout** – Sasmita Mar 19 '22 at 07:30