在editfield blackberry中键入字符时回调

时间:2012-12-31 08:56:26

标签: search blackberry focus blackberry-editfield

我需要在BlackBerry的EditField中输入或删除每个字符的回调。我需要在写完EditField时尽快得到{{1}}的文字,而不会失去焦点。

1 个答案:

答案 0 :(得分:1)

有多种方法可以做到这一点。例如,如果您有EditField这样的实例:

private EditField _editField;

然后你可以继承EditField并覆盖keyChar()方法:

_editField = new EditField() {
    protected boolean keyChar(char key, int status, int time) {
       super.keyChar(key, status, time);
       // 'key' is the most recent entered char
    }
});

或者,您可以实施FieldChangeListener并监听更改:

_editField.setChangeListener(new FieldChangeListener() {
    public void fieldChanged(Field field, int context) {
        String text = _editField.getText();
        // 'text' is the full text contents of the EditField
    }
});