How to define a delete key in my Field subclass?

I am trying to detect and override the Delete key on a Blackberry keyboard.

For some reason, it never makes it inside a case statement when it hits this point:

Keypad.key(keycode) == 8 Keypad.KEY_DELETE == 127 

What is my mistake?

 public class MyField extends ListField implements KeyListener { // ... /** Implementation of KeyListener.keyDown */ public boolean keyDown(int keycode, int time) { boolean retval = false; switch (Keypad.key(keycode)) { /* DELETE - Delete the timer */ case Keypad.KEY_DELETE: if (Keypad.status(keycode) == KeyListener.STATUS_SHIFT) { _myDeleteCmd.run(); retval = true; } break; default: retval = super.keyDown(keycode, time); } return retval; } 
+3
blackberry keyboard-events keylistener keydown
source share
1 answer

It is likely that the key event is consumed by another KeyListener.keyDown function before it can reach this field. You can easily verify this by setting a breakpoint in your keyDown () implementation to ensure that the application has reached that point.

To use a key event, the KeyListener function just needs to return true. Make sure that you do not return true for any other keyDown implementations by default, to ensure that each implementation uses only the keys that it uses.

+3
source share

All Articles