ListView的用键盘的EditText问题 [英] ListView with EditText Keyboard Issues

查看:179
本文介绍了ListView的用键盘的EditText问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序,我有一个活动,其中包含一个片段,其中包含一个ListView各种EditTexts,像这样:

In my app, I have an Activity, which contains a Fragment, which contains a ListView with various EditTexts, like so:

活动 - >片段 - > ListView控件 - > EditTexts

Activity -> Fragment -> ListView -> EditTexts

当一个EditText被窃听,显示软键盘和一两件事情发生:

When an EditText is tapped, the soft keyboard is displayed and one of two things happens:


  • 如果该活动尚未失去焦点(通过访问Android主屏幕,例如),整个活动以使EditText上不被键盘遮住微微向上滑动。

  • If the Activity has not yet lost focus (via visiting the Android home screen, for example), the entire activity slides up slightly so that the EditText is not obscured by the keyboard.

如果该活动已在某些时候(同样,如参观Android主屏幕)失去重心,在ListView滚动的EditText键盘上方(活动保持静止),但的EditText失去焦点!

If the Activity has lost focus at some point (again, such as visiting the Android home screen), the ListView scrolls the EditText above the keyboard (the activity remains stationary), BUT the EditText loses focus!

无论这些结果是理想的。理想情况下,我总是想在ListView滚动键盘没有的EditText失去焦点上面的EditText。任何人都可以点我在正确的方向和/或解释为何我看到两个不同的行为进行同样的动作,现在?

Neither of these results is ideal. Ideally, I always want the ListView to scroll the EditText above the keyboard without the EditText losing focus. Can anybody point me in the right direction and/or explain why I am seeing two different behaviors for the same action right now?

编辑:作为参考,我建立于Android 4.2和Nexus 7平板电脑测试

For reference, I'm building for Android 4.2 and testing on Nexus 7 tablet.

推荐答案

现在的问题是,当你在ListView行使用的EditText,你的ListView可能会重新绘制,使空间的键盘。当你的ListView重绘,系统不记得在哪里光标以前。

The problem is that when you use EditText in a ListView row, your ListView might be redrawn to make space for the keyboard. And when your ListView is redrawn, the system does not remember where the cursor was before.

同样的问题似乎没有,如果你使用的LinearLayout一个滚动型内发生
而不是一个ListView。这听起来很愚蠢,但它的工作原理。

The same issue does not seem to happen if you use a LinearLayout inside a ScrollView instead of a ListView. It sounds stupid, but it works.

这篇关于ListView的用键盘的EditText问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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