EditText失去了对RecyclerView中Scroll的关注 [英] EditText loses focus on Scroll in RecyclerView

查看:266
本文介绍了EditText失去了对RecyclerView中Scroll的关注的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 RecyclerView ,其中包含 EditText 作为其列表项。当我滚动 RecyclerView 时, EditText 在项目离开屏幕时失去焦点。所以焦点不会保留在 EditText 上,当它在滚动屏幕上显示时。

I have a RecyclerView which have EditText as its list items. When i scroll the RecyclerView, the EditText loses focus when the item goes off screen. So the focus does not remain on the EditText when it comes back on the screen on scroll.

我想要专注于保持同一项目。为此我还尝试在焦点上存储项目的位置,并在 onBindViewHolder 中重新分配焦点。但滚动速度减慢。

I want the focus to remain on the same item. For that i also tried storing position of the item on focus and reassigning the focus in onBindViewHolder. But that slow downs the scrolling.

我还尝试使用 ListView ,但还有另一种焦点相关问题。焦点跳到那里。

I also tried this with ListView but there is another kind of focus related problem. Focus jumps there.

已经搜索了很多关于SO和Google搜索的内容。但总能找到答案,如 android:focusableInTouchMode =true android:descendantFocusability =afterDescendants哪些不起作用。

Have searched for this lot on SO and Googled a lot. but always found answers like android:focusableInTouchMode="true" and android:descendantFocusability="afterDescendants" which does not work.

任何帮助都将受到高度赞赏。

Any help would be highly appreciated.

推荐答案

整体 RecyclerView 的重点是重用视图,这样手机就不必一次将所有行保留在内存中,也不必经常破坏和创建观点。当 EditText 离开屏幕时,手机会占用该视图,重置其内容并将其移至传入视图堆栈的底部。

The whole point of a RecyclerView is to reuse the views so that the phone doesn't have to keep all the rows in memory at once and doesn't have to be constantly destroying and creating views. When your EditText leaves the screen, the phone takes that view, resets its contents and moves it to the bottom of the incoming view stack.

这意味着一旦你的 EditText 离开屏幕不再存在。它无法保持焦点,因为它已从布局中删除。

This means that once your EditText leaves the screen it no longer exists. It cannot keep focus because it is removed from the layout.

唯一的解决方法就是你提到的,即存储位置,检查屏幕上的位置何时出现,并手动恢复焦点。

The only way around this would be what you mentioned, which is storing the position, checking when that position comes onscreen, and manually restoring focus.

这篇关于EditText失去了对RecyclerView中Scroll的关注的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆