I've got a few EditText fields in a ListView. When I tap on one of the EditText fields, the keyboard slides into view (as it should), but the EditText field I tapped loses focus. I've tried using various InputMethodManager methods to make the keyboard start out in view (in order to get around the problem rather than truly solve it), but that didn't work - the keyboard was not in view when the Activity appeared.
The EditText's type is number
, and when the keyboard is sliding in, it is a number keyboard, but when it finishes sliding and the EditText loses focus, it changes to the alphabetical keyboard (which reinforces the idea that the EditText no longer has focus).
My questions are these:
1) How can I make the selection of my EditText field and the subsequent sliding in of the soft keyboard not make my EditText lose focus?
... failing that...
2) How can I make the keyboard start out in view so it never has to slide in (thus avoiding the behavior I find so objectionable)?
My manifest does include android:windowSoftInputMode="stateAlwaysVisible"
, but the keyboard does not appear until I tap on an EditText. This ignoring of the 'stateAlwaysVisible' attribute seems to only occur in the emulator - on my provisioned device, it is honored so question number 2 above does work on the device... but not in the emulator.
Thanks for any help you can provide!
Here is how I did it. The
onFocusChangeListener()
is called several times when you touch aEditText
to type text into it. The sequence is:Target finally gains focus
The code above works well for the keyboard pop-ups. However, it does not detect the speech-to-text pop-up.
For those who come here with Xamarin or Xamarin.Forms:
I had the same issue as well but only with Android 5.x - all newer Versions including 8.1 worked well.
Obviously sheltond was right by saying:
My listview was resizing as well and no, Franks solution to set
windowSoftInputMode="adjustPan"
was no option for me because that means that the keyboard moves the listview partly off the screen.All I had to do after hours of focus-debugging was setting the cell caching strategy of the Xamarin Forms ListView:
From
To
This will stop the cells from being recreated. However, this might result in bad performance and high memory consumption for huge lists. Be aware.
In AndroidManifest.xml use adjustNothing in the activity that contain the views