dimanche 8 mars 2015

Showing and hiding the soft keboard does not work


Vote count:

0




Not sure if it's relevant but I'm using LG G3 with Android 4.4.2


I have a fragment where I want the keyboard to show, so I did the following:



txtContact = (EditText) rootView.findViewById(R.id.txtContact);
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(txtContact.getWindowToken(), InputMethodManager.SHOW_IMPLICIT);


and the layout is this, including requestFocus for the relevant field:



<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:ems="10"
android:lines="10"
android:layout_margin="10dp"
android:id="@+id/txtContact">

<requestFocus />
</EditText>


When opening this fragment, the cursor is where it should be but the keyboard is not there, Only when tapping inside the field, they appear.


The other problem is the opposite of the first one. On another fragment, I want to hide the keyboard when the fragment opens, no matter what. The reason for this, is that the user can open this fragment after closing a different one, where the keyboard was shown so I want to make sure it closes, notice that I don't know if the keyboard is shown, I want it to remain close if it was or to be closed if it was open. I only have a ListView in this fragment, so I did the following:



lv = (ListView) rootView.findViewById(android.R.id.list);
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(lv.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);


but it refuses to make any effect on the keyboard and it remains open.


What am I doing wrong?



asked 2 mins ago

Amos

85






Showing and hiding the soft keboard does not work

Aucun commentaire:

Enregistrer un commentaire