0

How can I hide soft keyboard on Spinner click when this Spinner is in ListView? Basically I want to hide keyboard when Spinner list with data is on.

Pradeep Gupta
  • 1,770
  • 1
  • 9
  • 23
y07k2
  • 1,898
  • 4
  • 20
  • 36
  • You can make a custom spinner with open and close events and when spinner is opened then you can close your keyboard programmatically in its open event code.Refer this link for reference. http://stackoverflow.com/questions/18447063/spinner-get-state-or-get-notified-when-opens – Jay Shah May 11 '16 at 13:08

2 Answers2

1

setOnFocusChangeListener Callback Listener For Spinner

Spinners.setOnFocusChangeListener(this);

 @Override
    public void onFocusChange(View view, boolean b) {

   if(view.getID()==R.id.do_excutive_spinner)
   {
       Hide_Key();
   }
}

Hide Virtual Keyboard Code

public void Hide_Key() {
    // Check if no view has focus:
    View view = getCurrentFocus();
    if (view != null) {
        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }
}
Community
  • 1
  • 1
Mallikarjuna
  • 874
  • 6
  • 17
0

Simply create this method:

public static void hideSoftKeyboard(View v) {
    InputMethodManager in = (InputMethodManager) v.getContext()
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    in.hideSoftInputFromWindow(v.getApplicationWindowToken(),
            InputMethodManager.HIDE_NOT_ALWAYS);
}

pass it the view object. Call this method when your spinner is opened or clicked. This should do it, if it does not work, let me know. I'll be happy to help.

vibhor_shri
  • 374
  • 2
  • 12