Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Posts: 157
Registered: ‎03-03-2009
My Device: Not Specified
Accepted Solution

cannot delete char on editField once keyChar is implemented

In the simple codes below, there is an editField in the screen. For Storm OS 4.7, once I input a word in the edit field, I cannot use the backspace key to delete any letter. The only way is to add a letter so that all letters are highlighted. Only then, the backspace key will work to delete letters.

 

If I commented out the keyChar method, I can add/delete letters freely. 

 

Am I missing something in the keyChar implementation and that cuased deleting letter being not possible?

 

Thanks

 

 

 

class HomeScreen extends UiApplication { public static void main(String[] args) { HomeScreen app = new HomeScreen(); app.enterEventDispatcher(); } HomeScreen() { pushScreen(new EditScreen()); } private class EditScreen extends MainScreen { EditScreen(){ add(new EditField(EditField.EDITABLE)); } protected boolean keyChar(char key, int status, int time){ boolean result = false; if (key == Characters.ESCAPE){ Dialog.alert("Escape key is pressed"); result = true; } return result; } } }

 

 

 

Highlighted
Developer
Posts: 5,339
Registered: ‎09-20-2008
My Device: ***
My Carrier: ***

Re: cannot delete char on editField once keyChar is implemented

[ Edited ]

protected boolean keyChar(char key, int status, int time){
if (key == Characters.ESCAPE){
Dialog.alert("Escape key is pressed");

 

// consuming event if escape pressed
return true;
} else {

// for non-escape keys passing call to the parent

return super.keyChar(key, status, time);
}
}

Message Edited by tbilisoft on 10-06-2009 07:23 PM