03-28-2011 02:03 PM
Hi,
I am wanting to write a paragraph of text and display this on the screen within my app. I'm sure I read that the TextField operation creates an editable text box on the screen. What way would you suggest to creating this paragraph? Would I simply use many LabelFields?
Thanks
Solved! Go to Solution.
03-28-2011 02:07 PM
You can use a TextField or its descendants (such as EditField) to display the text. If you make it NON_FOCUSABLE, the user will not be able to navigate to it. If you make it FOCUSABLE | READONLY, the user will be able to navigate there, select some text and copy it (to paste somewhere else, maybe), but will not be able to edit the contents.
Hope this helps.
03-28-2011 02:10 PM
Thanks for the swift response
How would I go about declaring the TextField and adding it to my existing code? Do you have an example to go by? Am I correct in assuming I will need to add it to my VerticalFieldManager backgroundManager.
03-28-2011 02:37 PM
Yes, just add it to your scrolling manager. It might look like this:
TextField copyrightField = new TextField(TextField.FOCUSABLE | TextField.READONLY); copyrightField.setText(myCopyrightText); mainVFM.add(copyrightField);
Simple but effective. In this particular case, if your text is too long and your manager is scrolling, the user will be able to scroll through the whole text with regular navigationMovements (trackball / trackpad, swipe / move on a touchscreen).
03-28-2011 04:47 PM
Hi,
I tried to add your suggestion but I receive certain errors and am not sure as to why this is.
TextField copyrightField = new TextField(TextField.FOCUSABLE|TextField.READONLY);
copyrightField.setText("Hello");
backgroundManager.add(copyrightField);
FOCUSABLE and READONLY are displaying errors, as are both "setText" and "add"
03-28-2011 04:59 PM
Made the TextField a RichTextField and this solved the issue
Thanks
Ash
03-28-2011 05:01 PM
There are two TextFields:
javax.microedition.ui.TextField
net.rim.device.api.ui.component.TextField
Make sure you are importing the second (highlighted) one.
03-28-2011 05:15 PM
Thanks for that. One other thing, do you know of a way to override the getPrefferedWidth() function for the size of the text box? At the minute the text overlaps with other items on my screen so I'd like to make the width smaller.
Thanks
03-28-2011 06:04 PM
This is a separate issue so you'd better start a new topic. Before you do that, though, search the board for "limit width", "layout override" and similar - you are bound to find something useful.
getPreferredWidth() is simply overridden, no tricks here. The problem is - parent managers totally ignore it when laying out the fields. RichTextField at least has USE_TEXT_WIDTH, but it is useless for text that is more than one line.
Oh, and if you start the new topic, please describe what do you mean by "overlaps with other items" - Fields do not normally overlap on the screen no matter what their width or "preferred width" is...
03-28-2011 06:06 PM
Hi,
I have just managed to overcome the issue by using setMargin()
Thanks for your help