This question already has an answer here:
- Focusable EditText inside ListView 12 answers
I have an EditText
inside each row of a ListView
. For some reason, when I tap the EditText, it briefly gains focus but then immediately loses it.
I have tried these things:
listView.setItemsCanFocus(true);
editText.setFocusable(true);
While the EditText
is (briefly) focused, the Enter
key says Next
and the auto-correct bar
is present. When it loses focus, the soft keyboard stays up, but the Enter
key becomes a Return Arrow
, and the auto-correct bar
disappears.
If you want list items to take focus, its pretty straight forward: Make the listview not focusable, and say that its focus is
afterDescendants
which letsEditText
s and other focusable items take focus.EditText
s withinListView
s are extremely tricky. I'd suggest you avoid them like the plague if possible. When I was messing with them, this answer was helpful though. If you only have a few items you can always just use aScrollView
.I know this question is old, but I was also fighting with EditText and ListView today. I think lose time with focus problem or updating dataset is the end of the line.
So, I created an Activity and dynamically added the controls I need. In this example I added two controls: a textview and edittext.
First I create a class to be a "container" of the controls and them I put the controls on a ScrollView.
The layout.xml file:
The "containter" class:
So, the main activity:
I hope it helps someone.