Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show keyboard for edittext when fragment starts

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?

like image 643
heero Avatar asked May 09 '12 00:05

heero


People also ask

How to open keyboard when fragment starts in android?

edit = (EditText) view. findViewById(R. id.search); InputMethodManager imgr = (InputMethodManager) getActivity().

How do I show soft keyboard when EditText is focused?

android:windowSoftInputMode="stateAlwaysVisible" -> in manifest File. edittext. requestFocus(); -> in code. This will open soft keyboard on which edit-text has request focus as activity appears.

How do I prevent the soft keyboard from pushing my view up in fragment?

Setting android:isScrollContainer = "false" inside the ScrollView worked for me. According to the documentation, settings "isScrollContainer" to true means that the scroll view can be resized to shrink its overall window so that there is space for an input method.


1 Answers

Does this work?

imgr.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY); 
like image 133
Sam Avatar answered Sep 20 '22 13:09

Sam