首页 > 解决方案 > 在 recyclerview 中提交列表后强制编辑文本以移除焦点

问题描述

我有一个具有多个编辑文本的回收站视图。在向 recyclerview 添加项目时,焦点始终转移到屏幕的第一个 editText。我已经将 android:focusable="true" 和 android:focusableInTouchMode="true" 与编辑文本的父布局一起使用。下面是我的片段的 XML 代码:

 <androidx.constraintlayout.widget.ConstraintLayout
                    android:id="@+id/layoutPickupLocation"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:focusable="true"
                    android:focusableInTouchMode="true"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent">

                    <ImageView
                        android:id="@+id/iv_origin"
                        android:layout_width="15dp"
                        android:layout_height="15dp"
                        android:layout_marginStart="8dp"
                        android:src="@drawable/ic_origin_icon"
                        app:layout_constraintBottom_toBottomOf="parent"
                        app:layout_constraintEnd_toStartOf="@+id/et_origin"
                        app:layout_constraintHorizontal_bias="0.0"
                        app:layout_constraintStart_toStartOf="parent"
                        app:layout_constraintTop_toTopOf="parent" />

                    <EditText
                        android:id="@+id/et_origin"
                        style="@style/textGreyLight"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_marginStart="6dp"
                        android:layout_marginEnd="@dimen/sixteen_dp"
                        android:background="@null"
                        android:imeOptions="actionDone"
                        tools:hint="Enter Pickup Location"
                        android:singleLine="true"
                        android:ellipsize="end"
                        android:textColor="@color/warm_grey"
                        android:textSize="14sp"
                        app:layout_constraintBottom_toBottomOf="parent"
                        app:layout_constraintEnd_toEndOf="parent"
                        app:layout_constraintStart_toEndOf="@id/iv_origin"
                        app:layout_constraintTop_toTopOf="parent" />
                </androidx.constraintlayout.widget.ConstraintLayout>

                <androidx.recyclerview.widget.RecyclerView
                    android:id="@+id/rv_places"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:overScrollMode="never"
                    app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toBottomOf="@id/layoutPickupLocation" />
            </androidx.constraintlayout.widget.ConstraintLayout>

这就是我将项目提交到我的 RecyclerView 列表的方式:

 private fun submitSearchResult(it: List<MultipleLocation>?) {
        mLocationSearchAdapter.submitList(it?.map {
            DataItemLocationSearchListing.DefaultItemListing(
                    it
            )
        })
        rvSearchLocation.post(Runnable { mLocationSearchAdapter.notifyDataSetChanged() })
    }

任何形式的帮助将不胜感激。

标签: androidkotlinandroid-recyclerviewandroid-edittextlistadapter

解决方案


notifyDataSetChanged()notifyItemChanged(positionOfYourList).


推荐阅读