Skip to content

Instantly share code, notes, and snippets.

@daichan4649
Created April 30, 2013 09:49
Show Gist options
  • Save daichan4649/5487732 to your computer and use it in GitHub Desktop.
Save daichan4649/5487732 to your computer and use it in GitHub Desktop.
エンター押下時にIME閉じる (for Android)
// EditText に listener を設定
// [EditText].setOnEditorActionListener(mEditorActionListener);
private OnEditorActionListener mEditorActionListener = new OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
hideIME(v);
}
return false;
}
private void hideIME(final TextView v) {
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(v.getWindowToken(), InputMethodManager.HIDE_IMPLICIT_ONLY);
imm.hideSoftInputFromWindow(v.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment