How do I detect the 'delete' key in my Field subclass?

一笑奈何 提交于 2019-12-10 18:35:11

问题


I'm trying to detect and override the Delete key on the Blackberry keyboard.

For some reason, it never makes it inside my case statement as when it hits that point:

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

What's my error?

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;
}

回答1:


It's likely that the key event is being consumed by another KeyListener.keyDown function before it is able to reach this Field. You can easily test this by setting a break point within your keyDown() implementation to make sure that the application reaches this point.

To consume a key event a KeyListener function just needs to return true. Make sure you aren't returning true by default for any other keyDown implementations to ensure that each implementation only consumes the keys that it uses.



来源:https://stackoverflow.com/questions/942037/how-do-i-detect-the-delete-key-in-my-field-subclass

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!