When my fragment starts, I want my edittext to be in focus/let user to just start typing in it. I am able to get it in focus with requestFocus(), but I cannot get the keyboard to show up.
I have tried both this:
edit = (EditText) view.findViewById(R.id.search);
edit.requestFocus();
InputMethodManager imgr = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imgr.showSoftInput(edit, 0);
and
edit = (EditText) view.findViewById(R.id.search);
InputMethodManager imgr = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imgr.showSoftInput(edit, 0);
edit.requestFocus();
How can I get the keyboard to show up for EditText?
Simply, using adding 2 lines will work like a charm:
If using XML
Else in Java:
EditText.requestFocus() + InputMethodManager.showSoftInput() = Show IME for EditText
use EditText.performAccessibilityAction(AccessibilityNodeInfo.ACTION_CLICK, null) in Fragment.onViewCreated() instead
or create subclass of EditText and override public InputConnection onCreateInputConnection(EditorInfo editorInfo)
Since using
showSoftInput
doesn't work for all cases and after trying some of the solutions mentioned here, like:I finally made it work using:
Since:
only request the focus for the
EditText
(it doesn't open the keyboard)and
is the only solution that appears to be working correctly to show the keyboard (and the most voted one)
Good luck! :-)
You can try this
As Nilzor said this works
and I agree it is a best solution than toogleSoftInput