Scroll nestedscrollview to bottom of textView

229 Views Asked by At

I have some editText in my activity so put them into nestedScrollView and my activity has the adjustResize attribute. I put a textView at bottom of each editText to show the exitText input error. But their visibility are Gone. When the soft-keyboard open I don't have a problem whit the first exitText, when I click on Next button of the soft-jetboard nestedScrollView scrolled to the bottom of next editText and if user write a wrong input to my editText the textView of them will be visible and show the error of input to the user.

BUT PROBLEM IS.

They are below of their editText. How I can scroll nestedScrollView to the bottom of the textView?

1

There are 1 best solutions below

0
On

You could just use TextInputEditText and TextInputLayout instead of EditText and TextView.

The scrolling behavior will be managed by Android's system and should result correctly.

Also, it will simplify your code:

    <com.google.android.material.textfield.TextInputLayout
        android:id="@+id/text_input_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        app:errorEnabled="true">

        <com.google.android.material.textfield.TextInputEditText
            android:id="@+id/text_input_edit_text"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="Hint"/>

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

You can set and remove errors with:

Java

text_input_layout.setError("Error message");
text_input_layout.setError(null);

Kotlin

text_input_layout.error = "Error message"
text_input_layout.error = null