I have a ListView
with edit text in each items and I want to know how can I make the EditText
editable.. It seems to work fine if I set the android:windowSoftInputMode="adjustPan"
into the manifest but only on some devices. On some devices the soft keyboard covers the edittext.
On the other side, if I don't put android:windowSoftInputMode="adjustPan"
in the manifest, the EditText
looses focus after the soft keyboard is displayed and I have to touch the EditText
multiple times to make it selected and can write in it.
Please help me solve this.
Note: I've seen this post: Focusable EditText inside ListView and nothing helped from there and I have totally other problem than that
I made a workaround for this though.. maybe will help someone
After unsuccessfully trying to create an interface with
EditTexts
inside aListView
all I can say to you is "Don't!". You'll be in much more trouble when you have enough items that you have to scroll yourListView
, focus will jump here and there, you'll have to save yourEditText
's state and so on. It seems like general idea is that usingEditText
inListView
is not worth it.After quite a bit of research I can suggest the following method that helped me: I've inherited
ListView
and overrided layoutChildren method, inside it I do the following:When I know which
EditText
should get the focus (I know this when my adapters getView is called) I set this particularEditText
as a tag toListView
. Then ListView lays out itself and my post thread is queued. It runs and requests focus, however since it wasn't enough in my case, I also generate twoMotionEvents
that simply simulate a tap. Apparently this is enough to make the soft keyboard appear. The reasons behind this are explained in an answer here: Android Actionbar Tabs and Keyboard Focus