键盘出现时 ListActivity 中的编辑文本 ListView 失去

Edit Text in ListActivity ListView loses focus when keyboard comes up(键盘出现时 ListActivity 中的编辑文本 ListView 失去焦点)
本文介绍了键盘出现时 ListActivity 中的编辑文本 ListView 失去焦点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经搜索并搜索了这个问题的答案,但所有看起来像是答案的东西都没有奏效,所以我想我会问的.

I have searched and searched for an answer to this question and everything that looked like an answer has not worked so I guess I will just ask.

我在 ListView 中添加了几个 EditText 框,这是 ListActivity 的基础.当我将 windowSoftInputMode 设置为 adjustPan 并单击 EditText 时,它会起作用,直到您再次单击它,然后键盘将其覆盖.当我使用 adjustResize 时,它可以工作,除非当键盘出现时 EditText 失去焦点,我必须再次点击它才能输入.

I have a couple of EditText boxes added to a ListView that is the basis to a ListActivity. When I set the windowSoftInputMode to adjustPan and click in an EditText it works until you click on it again and then the keyboard covers it up. When I use adjustResize it works except when the keyboard comes up the EditText loses focus and I have to tap on it again to type.

我试图弄清楚如何捕捉 onResize 但这似乎与视图相关联,而不是活动,我不完全确定如何听它.我还尝试了 EditText 框和 ListView 本身的各种可聚焦设置(如我阅读的其他帖子中所建议的那样),这些设置似乎也无济于事.

I was trying to figure out how to catch the onResize but that seems to be associated with the View and not the activity and I'm not entirely sure how to listen for it. I have also tried all sorts of focusable settings on the EditText boxes and the ListView itself (as suggested in other posts I read) that don't seem to help either.

推荐答案

您真正需要做的就是将它应用到您的 ListView:

All you really need to do is apply this to your ListView:

XML:

android:descendantFocusability="afterDescendants"

Java:

listView.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);

这篇关于键盘出现时 ListActivity 中的编辑文本 ListView 失去焦点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How to target newer versions in .gitlab-ci.yml using auto devops (java 11 instead of 8 and Android 31 instead of 29)(如何在.gitlab-ci.yml中使用自动开发工具(Java 11而不是8,Android 31而不是29)瞄准较新的版本)
Android + coreLibraryDesugaring: which Java 11 APIs can I expect to work?(Android+core LibraryDesugering:我可以期待哪些Java 11API能够工作?)
How to render something in an if statement React Native(如何在If语句中呈现某些内容Reaction Native)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Using Firebase Firestore in offline only mode(在仅脱机模式下使用Firebase FiRestore)
Crash on Google Play Pre-Launch Report: java.lang.NoSuchMethodError(Google Play发布前崩溃报告:java.lang.NoSuchMethodError)