简体   繁体   English

在列表视图中的EditText?

[英]EditText in a listview?

I have a ListView wich contains EditText views. 我有一个包含EditText视图的ListView。 When touching these EditText views, the soft key pad comes up (as desired). 触摸这些EditText视图时,将弹出软键盘(根据需要)。

When using android:windowSoftInputMode="adjustPan" the touch pad hides the bottom part of the ListView and thus possibly the EditText view in focus (just touched). 使用android:windowSoftInputMode =“ adjustPan”时,触摸板会隐藏ListView的底部,因此可能会隐藏EditText视图(只需触摸一下)。 I know that this can be solved by using android:windowSoftInputMode="adjustResize">. 我知道可以使用android:windowSoftInputMode =“ adjustResize”>解决。 However, in this case due to resizing the EditText view loses focus. 但是,在这种情况下,由于调整EditText视图的大小而失去了焦点。

I am now wondering whether it would be possible to both have the key pad not hide the EditText view and also have it not lose focus. 我现在想知道是否有可能既使键盘不隐藏EditText视图又使它不失去焦点。

Edited 已编辑

Try this code 试试这个代码

editText.setFocusable(true);
editText.setFocusableInTouchMode(true);
editText.setClickable(true);
editText.requestFocus();

of course the first three lines can be placed in xml layout with 当然,前三行可以放在xml布局中

android:focusable="true"
android:focusableInTouchMode="true"
android:clickable="true"

Then simply call editText.requestFoxus(); 然后只需调用editText.requestFoxus(); right after the key pad comes into view 键盘进入后

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM