[英]Android EditText in RecyclerView
I want to implement a search.我想实现一个搜索。 But unfortunately edit text must be in recycler view.
但不幸的是,编辑文本必须在回收者视图中。 I have multiple types of items.
我有多种类型的物品。 When user enters a letter I refresh whole adapter, searching is done locally.
当用户输入一个字母时,我会刷新整个适配器,搜索是在本地完成的。 That means that keyboard disappears and edit text is losing focus, because of this constant updating.
这意味着键盘消失,编辑文本失去焦点,因为这种不断更新。 I managed to fix it showing keyboard and focus an edit manually while binding.
我设法修复它显示键盘并在绑定时手动聚焦编辑。
if (item.inEditableMode) {
edit_text.requestFocus()
showKeyboard(edit_text)
}
But edit text works not that good as I expect.但是编辑文本的效果并不像我预期的那么好。 A problem can be seen when user types fast or wants to clear input.
当用户快速输入或想要清除输入时,就会出现问题。 Thanks for help.
感谢帮助。
"unfortunately edit text must be in recycler view" - I bet it do NOT have to be a part of RecyclerView
not part of Adapter
list item View
. “不幸的是,编辑文本必须在回收器视图中” - 我敢打赌它不必是
RecyclerView
的一部分,而不是Adapter
列表项View
。 better inspect your layout architecture instead of posted workarounds with hiding-showing (blinking) keyboard更好地检查您的布局架构,而不是使用隐藏显示(闪烁)键盘发布的解决方法
besides that even when it must be then don't notify whole Adapter
with notifyDataSetChanged()
, instead use notifyItemChanged(...)
- notify range of of your items, but not list item with EditText
- it won't be redrawn, so keyboard should stay visible and focus kept on that field.除此之外,即使必须如此,也不要使用
notifyDataSetChanged()
通知整个Adapter
,而是使用notifyItemChanged(...)
- 通知您的项目范围,而不是使用EditText
列出项目 - 它不会被重绘,所以键盘应保持可见,并专注于该领域。 still this isn't good approach, your EditText
should be separated from RecyclerView
almost for shure这仍然不是一个好方法,你的
EditText
应该与RecyclerView
几乎完全分离
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.