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: 40
Registered: ‎07-16-2008
My Device: Not Specified
Accepted Solution

Blocking the "Enter" press in BasicEditField

Hi,

 

i want to restrict the "Enter"  key press in Basic edit field..

 

i mean it should alow only one line...

 

how to do this...?

 

Developer
Posts: 507
Registered: ‎07-15-2008
My Device: Not Specified

Re: Blocking the "Enter" press in BasicEditField

Create a class that extends BasicEditField and override

 

 

protected boolean keyChar(char key, int status, int time)

 

 method of the field. Ignore all keys with code equals to Characters.ENTER and process all other keys.

And use this class in your code to get a field, that ignores "Enter" key.

 

----------------
if your issue solved set "Solution" mark at the relevant post
Developer
Posts: 507
Registered: ‎07-15-2008
My Device: Not Specified

Re: Blocking the "Enter" press in BasicEditField

Here is the sample of code:

 

 

protected boolean keyChar(char key, int status, int time) { if (key!=Characters.ENTER) { return super.keyChar(key, status, time); // passing non-enter keys to the parent } else { return true; // just ignoring Enter key, } }

 

 

 

----------------
if your issue solved set "Solution" mark at the relevant post
Developer
Posts: 19,631
Registered: ‎07-14-2008
My Device: Not Specified

Re: Blocking the "Enter" press in BasicEditField

Alternatively, you could try setting the style, for example:

BasicEditField bef = new BasicEditField(BasicEditField.NO_NEWLINE);