I want to automatically show the soft-keyboard when an EditText
is focused (if the device does not have a physical keyboard) and I have two problems:
When my
Activity
is displayed, myEditText
is focused but the keyboard is not displayed, I need to click again on it to show the keyboard (it should be displayed when myActivity
is displayed).And when I click done on the keyboard, the keyboard is dissmissed but the
EditText
stays focused and y don't want (because my edit is done).
To resume, my problem is to have something more like on the iPhone: which keep the keyboard sync with my EditText
state (focused / not focused) and of course does not present a soft-keyboard if there is a physical one.
I had the same problem in various different situations, and the solutions i have found work in some but dont work in others so here is a combine solution that works in most situations i have found:
You can try to force the soft keyboard to appear, it works for me:
To cause the keyboard to appear, use
This method is more reliable than invoking the InputMethodManager directly.
To close it, use
To hide keyboard, use this one:
and to show keyboard:
showSoftInput
was not working for me at all.I figured I needed to set the input mode: (here in the Activity component in the manifest)
The following code is pillaged from the Google's 4.1 source code for SearchView. Seems to work, fine on lesser versions of Android as well.
Then in addition, the following code needs to be added as the Control/Activity is created. (In my case it's a composite control, rather than an activity).