Code:

activityText.setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (event.getKeyCode() == KeyEvent.KEYCODE_ENTER || event.getKeyCode() == KeyEvent.KEYCODE_0 || keyCode == KeyEvent.KEYCODE_E){ Log.d("edit", "setOnKeyListener: "); return true; } return false; } }); 

Actually:

 event.getKeyCode() == KeyEvent.KEYCODE_ENTER не перехватывается event.getKeyCode() == KeyEvent.KEYCODE_0 перехватывается keyCode == KeyEvent.KEYCODE_E перехватывается 

This also does not work:

 activityText.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_DONE || actionId == EditorInfo.IME_ACTION_NEXT || actionId == EditorInfo.IME_ACTION_SEND || actionId == EditorInfo.IME_ACTION_GO){ Log.d("edit", "setOnEditorActionListener: "); } return false; } }); 

Are there any other ways to handle pressing Enter?

  • one
  • Working variant: 1. actionId == EditorInfo.IME_ACTION_DONE 2. in xml: android: imeOptions = "actionDone" android: inputType = "text" android: singleLine = "true" - Ya Si
  • mb just wrong button code? If you try to otdebazhit and press Enter, the interceptor will work (without conditions)? - George Chebotaryov
  • does not work. activityText.setOnKeyListener catches clicking on letters and numbers, but there is no Enter. Legacy code. - Ya Si

0