0

hi guys how to hide soft keypad when am changing the one view pager to another view pager

the problem is in view pager having four tabs,first tab having search option when i click search edit text then after i click another tab.soft key pad is visible in next tab.

how to reslove this problem, i tryed this way it's not working

((InputMethodManager) getActivity().getSystemService(Activity.INPUT_METHOD_SERVICE))
        .toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, 0);

help

venu
  • 2,971
  • 6
  • 40
  • 59

3 Answers3

0

Just add this attribute in your AndroidManifest under activity tag :

    <activity
        android:name="com.example.myApp.MyActivity"
        android:windowSoftInputMode="stateHidden" >
    </activity>
Manish Dubey
  • 4,206
  • 8
  • 36
  • 65
0

Try following code.

InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(any_focusable_view_reference.getWindowToken(), 0);

Here any_focusable_view_reference means EditText or such which has focus.

Chintan Rathod
  • 25,864
  • 13
  • 83
  • 93
0

just added setOnFocusChangeListener to Edittext , then it working fine .

EditText editTextProfileName = (EditText) view
                    .findViewById(R.id.nameEditText);

            editTextProfileName.setOnFocusChangeListener(new OnFocusChangeListener() {

                public void onFocusChange(View v, boolean hasFocus) {
                      if (!hasFocus) {
                            hideKeyboard();
                        }
                }

                private void hideKeyboard() {
                    if (editTextProfileName != null) {
                        InputMethodManager imanager = (InputMethodManager) getActivity()
                                .getSystemService(Context.INPUT_METHOD_SERVICE);
                        imanager.hideSoftInputFromWindow(editTextProfileName.getWindowToken(), 0);

                    }

                }
            });

Thanks

venu
  • 2,971
  • 6
  • 40
  • 59