fiddler fiddler - 2 years ago 171
Android Question

Android TextField : set focus + soft input programmatically

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

. The field actually gets focus but soft keyboard is not displayed.

I tried
. But that only calls the OnClickListener of the field.

Any idea ?

Answer Source

Good sir, try this:


Im not sure, but this might be required on some phones (some of the older devices):

final InputMethodManager inputMethodManager = (InputMethodManager) context
inputMethodManager.showSoftInput(edittext, InputMethodManager.SHOW_IMPLICIT);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download