0

I am trying to get the delete key remove characters like a typical backspace key. MyEditField is a subclass of EditField, and the stock EditField contains three methods, protected int backspace( int count, int context ), public int backspace( int count ), and protected boolean backspace().

MyEditField is set to FILTER_REAL_NUMERIC when instantiated, and I have tried using all the above methods to get the delete key to work. Is it necessary to override the backspace functions to get to work, or am I going to have to write a custom algorithm to get the delete key to remove a character at the end of the string?

I have read the documentation, and I could not find any mention of when the backspace functions will work and when they will not. Also, I know the system (a.k.a. simulator) is registering a key press on the delete since I can print the key code to the console.

I am trying get something more user friendly than having to go through the BB menu to clear the entire field.

CRUSADER
  • 5,486
  • 3
  • 28
  • 64
Mike D
  • 4,938
  • 6
  • 43
  • 99

1 Answers1

2

Is it necessary to override the backspace functions to get to work

No, it isn't. Just catch the key event and call backspace(). Smth like:

protected boolean keyChar(char key, int status, int time) {
    if (key == Characters.DELETE) {
        backspace();
        return true;
    }
    return super.keyChar(key, status, time);
}
Vit Khudenko
  • 28,288
  • 10
  • 63
  • 91
  • Was wondering if you were going to answer. This kind of works. But it 2 chars at a time. – Mike D Apr 13 '11 at 18:31
  • @Mike D: 2 chars... Odd. Do you use exactly the code I posted? Another point where it can still leak is `keyControl(char key, int status, int time)`, so just in case make sure you catch the same key there and return true (so the event is consumed). – Vit Khudenko Apr 13 '11 at 18:46
  • I am. Could there be conflict the main screen listening for the enter key? – Mike D Apr 13 '11 at 19:36
  • @Mike D: I do believe that key events are passed to the leaf field that is responsible to hande those events (so only your edit field decides what to do with event). Otherwise it were a total mess. So I don't believe in your theory. Have you overriden the `keyControl(char key, int status, int time)` in your field? – Vit Khudenko Apr 14 '11 at 08:41