0

I have a custom view which looks something like this:

<LinearLayout
    android:orientation="vertical">
    <TextInputLayout>
        <TextInputEditText />
    </TextInputLayout>
    <TextView
        android:text="Some info text" />
</LinearLayout>

It's basically a normal edit text with hint, which has "info" text underneath.

The problem comes in when I try to requestFocus() on the custom view. It correctly places the cursor in the edit text, but only scrolls to the bottom of the edit text. The "info" text is therefore "hidden" until the user scrolls down a bit.

Is it possible to tell the custom view what its "focus area" is? Or perhaps another mechanism which makes the system scroll correctly (i.e. scroll to the bottom of the "info" text?

Any help will be appreciated. Thanks.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115

1 Answers1

0

Calll this method and pass the variables of your EditText and ScrollView,

  private void focusOnView(ScrollView scrollView, EditText editText) {
    scrollView.post(new Runnable() {
        @Override
        public void run() {
            scrollView.scrollTo(0, editText.getBottom());
            editText.requestFocus();
        }
    });
}

And done

Sana
  • 456
  • 3
  • 9