Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

After type in EditText, how to make keyboard disappear

From the android tutorial :

pass_text.setOnKeyListener(new OnKeyListener() {
    public boolean onKey(View v, int keyCode, KeyEvent event) {
        // If the event is a key-down event on the "enter" button
        if ((event.getAction() == KeyEvent.ACTION_DOWN)
                && (keyCode == KeyEvent.KEYCODE_ENTER)) {
            // Perform action on key press
            return true;
        }
        return false;
        }
    });
}

when click at EditText, it has a keyboard appear on the frame. I want to know after Enter. How to make keyboard out from frame except click Back.

enter image description here

Thank you

like image 834
Yoo Avatar asked Jan 30 '11 04:01

Yoo


3 Answers

Try the following

For Activity:

InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
mgr.hideSoftInputFromWindow(curEditText.getWindowToken(), 0);

In case of Fragment :

InputMethodManager mgr = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
        mgr.hideSoftInputFromWindow(mEditText.getWindowToken(), 0);
like image 69
Nick Campion Avatar answered Nov 19 '22 10:11

Nick Campion


give the EditText box you have the attribute android:imeOptions="actionDone" this will change the Enter button to a Done button that will close the keyboard.

like image 16
Nathan Schwermann Avatar answered Nov 19 '22 09:11

Nathan Schwermann


A working approach to get rid of the soft keyboard is to disable and then enable the TextEdit field in the Return-key event, button-press event or whatever. For example:

....
pass_text.setEnabled(false);
pass_text.setEnabled(true);
....
like image 1
CodingForFun Avatar answered Nov 19 '22 10:11

CodingForFun