07-09-2010 12:37 PM
Hi Dee,
This should work without any problem.
Post your code snippet that causing the error.
Regards
Bikas
07-09-2010 01:53 PM
To the original question:
You don't need all that complicated code to work. Rely on the BlackBerry primitives - they are written in the native code and are much more efficient at what they do, not to mention work well together.
So, you want a horizontally scrollable EditField which will never go to the second line on its own. Since Fields do not scroll by themselves (they might, but the documentation does not mention that, so assume they don't), you need something horizontally scrollable. Hey - isn't HorizontalFieldManager what you are looking for?
HorizontalFieldManager myHfm = new HorizontalFieldManager(HorizontalFieldManager.HORIZONTAL_SCROLL);
You may add HORIZONTAL_SCROLLBAR or NO_HORIZONTAL_SCROLLBAR if you like.
Now, since this Manager will let the fields inside have virtually infinite horizontal space (0x3FFFFFFF pixels), your EditField should never wrap on its own. So a regular EditField will do. Something like this:
EditField myEditField = new EditField("My label: ", "my initial text", EditField.DEFAULT_MAXCHARS, EditField.FOCUSABLE);
Add the edit field to your Manager and your Manager to your screen (or another Manager which will contain that)
myHfm.add(myEditField); add(myHfm);
Isn't it simpler?
Of course, your label will scroll away if you type too many characters. If you want it to stay, move it out into a LabelField; create an additional, non-scrollable HorizontalFieldManager; add your LabelField and your scrollable HorizontalFieldManager to it; add your EditField to your scrollable HorizontalFieldManager; and finally, add your non-scrollable HorizontalFieldManager to your Screen.
That works like a charm, behaves much better on Storm devices (because RIM internal classes are supplied by the OS which has device-specific versions) and is overall faster and easier to debug.
Oh, one last thing: if you want your EditField to always be on one line, disable ENTER key processing (which inserts new line and re-layouts your EditField). Like this:
EditField myEditField = new EditField(...) {
protected boolean keyChar(char c, int status, int time) {
if (c == Characters.ENTER) {
return true;
}
return super.keyChar(c, status, time);
}
};
08-30-2011 11:41 AM
Since the time I had posted the above reply, I've created a knowledge base article on the topic. The article is much more mature and definitely more thoroughly commented and explained. I've also provided some additional ideas in the comments to it.
So for all future readers - here is the link to the article:
Scrollable one-line text input field
I hope it proves useful to you.
09-18-2011 11:15 AM
Hi,
this code really helps me but i want to scoll vertically also i tried a lot but nothing done it only scroll horizontally.
what actually i want is that when text reached to the end of lenghtof textbox then data return from new line.
i think you understand my problem.
thanks & regards
milan
09-18-2011 12:14 PM
I add this style EditField.NO_NEWLINE to my edifields to make sure the text stays on one line. Not sure if this is what you were trying to achieve....just wanted to mention it.
09-18-2011 07:13 PM
milanvishal wrote:
Hi,
this code really helps me but i want to scoll vertically also i tried a lot but nothing done it only scroll horizontally.
what actually i want is that when text reached to the end of lenghtof textbox then data return from new line.
i think you understand my problem.
thanks & regards
milan
Next time, please start a new topic - your post is absolutely contrary to the original goal of this one (the OP here wanted to text not to wrap; you want it to wrap).
Anyway, I'm pretty sure you need the following knowledge base article instead:
09-19-2011 01:33 AM