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.
Asked
Active
Viewed 144 times
-1
-
1You forgot the "keylogger" tag. – Linus Kleen Dec 31 '12 at 08:58
-
@LinusKleen, why do you assume this is for a key logger? There's plenty of legitimate use cases for this. Especially on mobile devices, where you don't want the user to have to press any more keys than necessary (e.g. **Enter**), this makes sense. Or for auto-complete. Besides, the answer(s) this question is likely to get, on BlackBerry, aren't going to let you *log* keys in any app other than your own. Not to mention that this is almost certainly in support of [this other question](http://stackoverflow.com/q/14098719/119114). – Nate Dec 31 '12 at 10:12
-
1This is a legitimate BlackBerry question - it was closed far too hastily. I am nominating it for 'reopen' – Michael Donohue Jan 06 '13 at 20:45
1 Answers
1
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
}
});

Nate
- 31,017
- 13
- 83
- 207
-
You're welcome. I don't know if you can *accept* an answer once the question has been closed, but if there is a little checkmark icon ("V") next to this answer, please click it to indicate that this solved the problem. Thanks! – Nate Jan 04 '13 at 08:00