ListView 与 EditTexts 中的奇怪软键盘行为
我有一个充满 EditTexts 的 ListView。它们在启动时无法聚焦,但用户可以在长按 ListView 项(相应的 ListView)后进入“编辑模式”。 第一个奇怪的事情是当第一次长点击发生时。 EditText 获得焦点,但键盘不出现。需要点击 EditText 才能最终出现。之后长按另一个列表项时,会出现键盘。我设法观察到的内部行为的唯一区别是,在第一种情况下, onClick 事件不会触发 EditText,而在第二种情况下,它会触发。
但最令人沮丧的事情有时会发生,当我编辑几个项目,到处滚动,再编辑几个项目时,突然我最终进入一个聚焦的 EditText,没有显示键盘,也没有任何方法在该 EditText 中再次调出键盘,敲击没有帮助。 我在 apadter 中尝试非常小心,保存 EditText 状态并在 getView 方法的 ListView 适配器中重新创建它。
关于如何调试这个东西有什么建议吗?也许,有人可以解释键盘如何决定显示,以及如何调试此事件(如果可能)。
I have a ListView filled with EditTexts. They are unfocusable on start, but user may enter "edit mode" after long clicking a ListView item - the corresponding ListView.
The first weird thing is when the very first long click happens. EditText gets focus, but the keyboard does not appear. EditText needs to be tapped for it to finally appear. When after that the other list item is long clicked, the keyboard appears. The only difference in internal behaviour I managed to observe is that in the first case onClick event doesn't fire to EditText, while in the second case it does.
But the most frustrating thing happens sometime when I edit a couple of items, scroll here and there, edit a couple more and suddenly I end up in a focused EditText without keyboard shown and without any way to bring the keyboard up again in that EditText, tapping doesn't help.
I try to be really careful in my apadter and I save EditText state and re-create it in my ListView adapter in getView method.
Any suggestions on how to debug this stuff? Perhaps, someone could explain how the keyboard decides to show up, and how to debug this event if it's possible.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在这里找到了有关 requestFocus() 调用发生情况的非常好的解释:
Android 操作栏选项卡和键盘焦点
简而言之:当您调用 requestFocus() (或者由于布局中的 xml 设置而调用它)而整个视图树尚未布局时,您的视图会认为它具有焦点,但实际上可能没有。
一种解决方案是在布局完成后在您的视图或其父视图上调用 post(Runnable) 来请求焦点。
I've found a really good explanation of what's going on with requestFocus() calls here:
Android Actionbar Tabs and Keyboard Focus
In a couple of words: when you call requestFocus() (or it's called due to xml setting in layout) while the whole view tree isn't laid out yet, your view would think that it has focus but in fact it might not.
One solution would be calling post(Runnable) on your view or it's parent to request focus after layout is done.