/ Published in: Java
I kinda assumed the keyboard would automatically close when the ENTER key is pressed, but no it doesn't... Here's how..
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
textInput = (EditText)findViewById(R.id.textInput); textInput.setInputType( InputType.TYPE_TEXT_VARIATION_URI ); // optional - sets the keyboard to URL mode // kill keyboard when enter is pressed textInput.setOnKeyListener(new OnKeyListener() { /** * This listens for the user to press the enter button on * the keyboard and then hides the virtual keyboard */ // If the event is a key-down event on the "enter" button { InputMethodManager imm = (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(textInput.getWindowToken(), 0); return true; } return false; } } );