A simple solution:
You can set the EditField cannot accept the ENTER key and set the maximum number of characters.
EditField Loginidfield = new EditField ("Login", "Hello", Max_chars, Editfield.no_newline);
However, if the user is typing a character that is less than the maximum number of characters, but exceeds the length of the EditField, EditField will still wrap the line.
Solution:
Create a custom component that puts the EditField in the HorizontalFieldManager, and HorizontalFieldManager uses horizontal_scroll style to not break the line but can input many characters, Even if it's too long, it won't wrap.
* Http://www.dogizmo.com/gadget/sample-code-scrollable-one-line-text-input-field * *
Package Com.rim.samples.device.helloworlddemo;
Import Net.rim.device.api.system.Display;
Import Net.rim.device.api.ui.component.EditField;
Import Net.rim.device.api.ui.component.ListField;
Import Net.rim.device.api.ui.container.HorizontalFieldManager;
public class Onelinetextfield extends HorizontalFieldManager {
Private EditField _editfield;
Public Onelinetextfield (String label, string initialvalue, int maxchars, long style) {
Super (Horizontal_scroll);
_editfield = new EditField (label, InitialValue, Maxchars, style | Editfield.no_newline | editfield.focusable | editfield.editable);
Add (_editfield);
}
/*
protected void sublayout (int maxwidth, int maxheight) {
Super.sublayout (Getpreferredwidth (), maxheight);
}
public int getpreferredwidth ()
{
return 200;
}
*/
public String getText () {
return _editfield.gettext ();
}
}