【问题标题】:Force Edit text to remove focus after submitting list in recyclerview在 recyclerview 中提交列表后强制编辑文本以移除焦点
【发布时间】:2021-10-08 18:08:09
【问题描述】:

我有一个包含多个编辑文本的回收站视图。在向 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() })
    }

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

【问题讨论】:

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


    【解决方案1】:

    请将您的notifyDataSetChanged() 替换为notifyItemChanged(positionOfYourList)

    【讨论】:

      猜你喜欢
      • 2020-11-19
      • 1970-01-01
      • 1970-01-01
      • 2019-02-04
      • 2011-01-27
      • 2016-05-30
      • 2013-01-13
      • 1970-01-01
      • 2011-12-18
      相关资源
      最近更新 更多