-1

I've noticed the problem with EditText focus when I tapped on it. Generally, I have NestedScroll with RecyclerView in which I have a few EditText controls. After tapping one of it is presenting keyboard, but after that my focus is set to first EditTest from the top, not exact this one which I tapped.

Do you have any suggestion how can I resolve this problem?

Below I put the example of my activity layout.

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:padding="@dimen/general_padding"
android:background="@color/window_color">

<android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:focusableInTouchMode="true"
        android:orientation="vertical">

        <LinearLayout
            android:id="@+id/genericSection"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <!-- Title -->
            <LinearLayout
                android:id="@+id/titleContainer"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">

                <include layout="@layout/item_formt_element_title" />
                <include layout="@layout/item_formt_element_single_separator" />

            </LinearLayout>

            <!-- Tags -->
            <LinearLayout
                android:id="@+id/tagsContainer"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">

                <include layout="@layout/item_formt_element_tags" />
                <include layout="@layout/item_formt_element_single_separator" />

            </LinearLayout>

        </LinearLayout>

        <!-- Form elements -->
        <android.support.v7.widget.RecyclerView
            android:id="@+id/formRecyclerView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:focusableInTouchMode="true"
            app:layout_constraintTop_toBottomOf="@id/genericSection"/>

        <!-- Footer -->
        <View
            android:layout_width="match_parent"
            android:layout_height="20dp"
            android:background="@drawable/rounded_bottom"
            android:layout_marginBottom="@dimen/general_padding_bottom"
            app:layout_constraintStart_toStartOf="@id/formtsRecyclerView"
            app:layout_constraintEnd_toEndOf="@id/formtsRecyclerView"
            app:layout_constraintTop_toBottomOf="@id/formtsRecyclerView"/>

    </LinearLayout>

</android.support.v4.widget.NestedScrollView>

Gie
  • 1,907
  • 2
  • 24
  • 49

1 Answers1

0

You haven't shared code. Have you tried using request focus in your onClick method?

public void onClick(View v) {
EditText ed = v.findViewById(R.id.yourEditText);
ed.requestFocus();
}
Sharone Lev
  • 791
  • 7
  • 15
  • I would probably bind the EditText on create and leave the request focus inside the onclicklistener, but other than that this should work just fine! – Nikos Hidalgo Feb 13 '19 at 08:45
  • the View he gets here is the specific row in recyclerview so you won't be able to put this line in on create – Sharone Lev Feb 13 '19 at 08:58