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 ?
Good sir, try this:
edittext.setFocusableInTouchMode(true); edittext.requestFocus();
I'm not sure, but this might be required on some phones (some of the older devices):
final InputMethodManager inputMethodManager = (InputMethodManager) context .getSystemService(Context.INPUT_METHOD_SERVICE); inputMethodManager.showSoftInput(edittext, InputMethodManager.SHOW_IMPLICIT);
Here is the code that worked for me.
edittext.post(new Runnable() { public void run() { edittext.requestFocusFromTouch(); InputMethodManager lManager = (InputMethodManager)getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); lManager.showSoftInput(edittext, 0); } });
That's it! Enjoy ;)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With