简体   繁体   中英

Strange soft keyboard behavior in ListView with EditTexts

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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