打开键盘后更改EditText焦点

时间:2019-02-13 08:07:00

标签: android kotlin android-recyclerview android-edittext android-textinputedittext

当我点击它时,我已经注意到EditText焦点的问题。通常,我有带有RecyclerView的NestedScroll,其中有一些EditText控件。点击其中一个后,将显示键盘,但是此后,我的焦点从顶部开始设置为第一个EditTest,与我所点击的那个不完全相同。

您有任何建议如何解决此问题?

下面我以活动布局为例。

<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>

1 个答案:

答案 0 :(得分:0)

您尚未共享代码。您是否尝试过在onClick方法中使用请求焦点?

public void onClick(View v) {
EditText ed = v.findViewById(R.id.yourEditText);
ed.requestFocus();
}
相关问题