I am trying to respond to pressing the enter button on a standard system on screen soft keybord, in numeric mode. keyboard appears on the screen when myCustomEditText class is given focus.
tried 2 approaches:
- overriding
onKeyDown()
:
public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_ENTER) { //do sth.. return true; } return super.onKeyDown(keyCode, event); }
- setting listener
setOnKeyListener
:
myCustomEditText.setOnKeyListener(new OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_ENTER) { onRightButtonClicked(); return true; } return false; } });
(also tried onKeyDown()
in myCustomEditText as well, but with no effect)
problem is:
these aproaches above works for all the keys being pressed but for the enter key - the methods are not even being fired at all. (it's not a problem of bad KeyEvent.KEYCODE_...
)
my question is: why these methods are not being fired for enter key, but are for other keys, and how to listen to enter key being pressed properly?