Hide keyboard when “Edit text in recycler” scrolls from screen

I have RecyclerViewone containing EditTextchildren. I would like to hide the soft keyboard when the selected one EditTextscrolls from the screen. How can I find out when it is EditTextno longer displayed on the screen? Is there any event listener that I can attach to an element EditTextto tell?

+10
source share
3 answers

Contribute onTouchListeneras follows:

yourRecycleView.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {

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

        return false;
    }
});
+19
source
yourRecycleView.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {

            edittext.clearFocus(); //hidden keyboard 
            return false;
      }
});
0
source

:

editText.setOnFocusChangeListener((v, hasFocus) -> {
            Handler handler = new Handler();
            if (!hasFocus) {
                handler.postDelayed(() -> {
                    if (!editText.hasFocus()) {
                        InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
                        imm.toggleSoftInput(0, 0);
                    }
                }, 200);

            }
        });
0

Source: https://habr.com/ru/post/1667485/


All Articles