android - 在 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() })
}
任何形式的帮助将不胜感激。
解决方案
请notifyDataSetChanged()
用notifyItemChanged(positionOfYourList)
.
推荐阅读
- express - NextJS 一致地访问每个页面的请求对象
- azure-aks - 从启用了 api-server-authorized-ip-ranges 的私有 IP 范围访问 AKS API
- javascript - 使用js循环打印DOM上的html实体
- c - 机器级代码是什么意思以及如何查看它?
- android - Android kotlin 类型继承失败
- angular - Rest api不能从角度工作,但从邮递员调用时它很好
- excel - 在 PowerQuery 中使用 OR 逻辑连接两个表
- deno - 如何在 Deno 中创建一个空文件?
- r - 我应该如何在函数内的 R 中创建嵌套的并行 foreach 循环?
- wpf - AvalonDock 文档视图内容在浮动窗口后消失