how to hide virtual keyboard on touch of a spinner

陌路散爱 提交于 2019-12-04 22:48:18

Try this code, I hope it will work for you.

mSpinner.setOnTouchListener(new OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent event) {
                InputMethodManager imm=(InputMethodManager)getApplicationContext().getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(mEditText.getWindowToken(), 0);
                return false;
            }
        }) ;
Thunder

If you are having Spinner and EditText on an activity then this is the problem you are gonna feel for sure ,

call onTouchListener on your spinner and inside that take the reference of your edittext and hide softkeyboard.

 mySpinner.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            InputMethodManager inputMethodManager=(InputMethodManager)getApplicationContext().getSystemService(Context.INPUT_METHOD_SERVICE);
            inputMethodManager.hideSoftInputFromWindow(mReuestBloodActNotes.getWindowToken(), 0);
            return false;
        }
    }) ;

Try this:

// hide the keyboard if open
            inputManager.hideSoftInputFromWindow(getParent().getCurrentFocus()
                    .getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!