Home > OS >  How to disable error check on TextInputEditText when I press "next" action?
How to disable error check on TextInputEditText when I press "next" action?

Time:12-10

I have 3 TextInputEditText and I want to focus on the next field by pressing the "next" key of my keyboard. The problem is that I can't go to another TextInputEditText because of the "Source is black " error:

enter image description here

How I can bypass this error and go forward on the next field when I press "next" button of my keyboard?

Here is my code:


                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal"
                    app:layout_constraintTop_toBottomOf="@id/card2_title">

                    <LinearLayout
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:orientation="horizontal">

                        <com.google.android.material.textfield.TextInputLayout
                            android:id="@ id/corrente_i_1_til"
                            style="@style/AppTheme.TextInputLayout"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_marginTop="@dimen/margin_large"
                            app:errorEnabled="false">

                            <com.google.android.material.textfield.TextInputEditText
                                android:id="@ id/corrente_i_1_value"
                                style="@style/AppTheme.TextInputEditText"
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:inputType="number" />

                        </com.google.android.material.textfield.TextInputLayout>

                        <com.google.android.material.textfield.TextInputLayout
                            android:id="@ id/corrente_i_2_til"
                            style="@style/AppTheme.TextInputLayout"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_marginTop="@dimen/margin_large"
                            app:hintEnabled="false"
                            app:errorEnabled="false">

                            <com.google.android.material.textfield.TextInputEditText
                                android:id="@ id/corrente_i_2_value"
                                style="@style/AppTheme.TextInputEditText"
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:inputType="number" />

                        </com.google.android.material.textfield.TextInputLayout>

                        <com.google.android.material.textfield.TextInputLayout
                            android:id="@ id/corrente_i_3_til"
                            style="@style/AppTheme.TextInputLayout"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_marginTop="@dimen/margin_large"
                            app:errorEnabled="false">

                            <com.google.android.material.textfield.TextInputEditText
                                android:id="@ id/corrente_i_3_value"
                                style="@style/AppTheme.TextInputEditText"
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:inputType="number" />
                        </com.google.android.material.textfield.TextInputLayout>
                </LinearLayout>

CodePudding user response:

You can add a KeyListener to the EditText and then set the error to null when pressing NEXT

findViewById(R.id.corrente_i_2_value).setOnEditorActionListener { view, actionId, _ ->
    if (actionId == EditorInfo.IME_ACTION_NEXT) {
        view.error = checkInput() //This will return the error string or null if there is no error
        true
    } else {
        false
    }
}

CodePudding user response:

I understand its behavior In my code I have this:

textview.setOnEditorActionListener { _, actionId, _ ->
        when (actionId) {
            EditorInfo.IME_ACTION_NEXT ->
                if (validity == Validity.Valid) false
                else {
                    done = true
                    notifySourceChanged()
                    true
                }
            EditorInfo.IME_ACTION_DONE ->
                if (validity == Validity.Valid) false
                else {
                    done = true
                    notifySourceChanged()
                    true
                }
            else -> false
        }
    } 

and the "validity" is a "requireNotBlank" property So I solved myself by removing this check, thank you!

  • Related