In my view, I have a search EditText and I would like to trigger programmatically the behaviour of a click event on the field, i.e give focus to the text field AND display soft keyboard if necessary (if no hard keyboard available).
I tried field.requestFocus()
. The field actually gets focus but soft keyboard is not displayed.
I tried field.performClick()
. But that only calls the OnClickListener of the field.
Any idea ?
Here is the code that worked for me.
That's it! Enjoy ;)
The following code worked for me, after the other two answers didn't work for me:
Where
ShowKeyboard
isAfter a successful input, I also make sure I hide the keyboard
Technically, I just added 300 ms of delay before running the soft keyboard display request. Weird, right? Also changed
requestFocus()
torequestFocusFromTouch()
.EDIT: Don't use
requestFocusFromTouch()
it gives a touch event to the launcher. Stick withrequestFocus()
.EDIT2: In Dialogs (
DialogFragment
), use the followinginstead of
Good sir, try this:
Im not sure, but this might be required on some phones (some of the older devices):