質問

I need to get a callback with every character typed or deleted in EditField in BlackBerry. I need to get the text of EditField as soon as it is written, without losing focus.

役に立ちましたか?

解決

There's multiple ways to do this. For example, if you have an EditField instance like this:

private EditField _editField;

then you can subclass EditField and override the keyChar() method:

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

or, you can implement a FieldChangeListener and listen for changes:

_editField.setChangeListener(new FieldChangeListener() {
    public void fieldChanged(Field field, int context) {
        String text = _editField.getText();
        // 'text' is the full text contents of the EditField
    }
});
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top