Android Hide Soft Keyboard from EditText while not losing cursor

This worked for me:

        // Update the EditText so it won't popup Android's own keyboard, since I have my own.
    EditText editText = (EditText)findViewById(R.id.edit_mine);
    editText.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            v.onTouchEvent(event);
            InputMethodManager imm = (InputMethodManager)v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
            if (imm != null) {
                imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
            }                
            return true;
        }
    });

Leave a Comment