How to make the keyboard go away when typed

O my acer tablet, return will not replace by executing the following xml, but it does on my other 2 Android devices. So I was going to use the return key to exit the keyboard, as a back-up, the problem was, I figured out how to make a callback when key press, press but don’t know how to make the keyboard go away, code

mUserName=(EditText)findViewById(R.id.viewUserName); mUserName.setOnEditorActionListener( new android.widget.TextView.OnEditorActionListener() { public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { // goes here when enter is press return false; } } ); 
+4
source share
1 answer

In the xml for the edit text, set imeOptions. Basically just add this line:

 android:imeOptions="actionDone" 

This will change the enter button to the Finish button and release the keyboard when pressed.

-OR -

You can add this inside the code block above.

 InputMethodManager imm = (InputMethodManager)getSystemService( Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(mUserName.getWindowToken(), 0); 
+5
source

All Articles