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
Contributor
Musipoo
Posts: 41
Registered: ‎02-04-2013
My Device: Bold 9900
My Carrier: Vodafone

Automatically inserted empty lines in multiline LabelFields / RichtTextFields on device

[ Edited ]

Hey there,

 

I'm trying to display a pretty long string in multiple lines, on my Simulator it looks fine but when I test it on a real device it somehow automatically inserts an empty line every 4 or 5 lines of text.

The string I get from a webservice is fine, I already checked it. I tried displaying it with RichTextFields and LabelFields but the effect stays the same.

 

Does anyone know how to avoid that? I'm almost done with the application, there's just this small formatting problem - any help would be so appreciated!!

 

I'm not doing anything special with it I guess:

 

RichTextField text = new RichTextField(mainScreen.array[clickedItem][5]); 
			text.setFont(subtitleFont);
			text.setMargin(5,0,5,10); 
			
			add(text); 

 

Please use plain text.
Developer
peter_strange
Posts: 19,598
Registered: ‎07-14-2008
My Device: Not Specified

Re: Automatically inserted empty lines in multiline LabelFields / RichtTextFields on device

Can you replicate the problem with a String that you create yourself?

 

Can you check the contents of the string you are getting from the web service - debug on device perhaps. 

 

Also have you correctly decoded the bytes?  If you are being sent UTF-8 encoded bytes and converting them from bytes to String without specifying UTF-8, you could be getting rubbish inserted in places. 

Please use plain text.
Contributor
Musipoo
Posts: 41
Registered: ‎02-04-2013
My Device: Bold 9900
My Carrier: Vodafone

Re: Automatically inserted empty lines in multiline LabelFields / RichtTextFields on device

I can see the XML string the webservice is sending, which is okay. Additionally I tested getting this content into my app before and just displayed it with setScreenTest(), this one also worked out.

So the empty lines must be inserted when adding it to a LabelField or a RichTextField..

Please use plain text.
Developer
peter_strange
Posts: 19,598
Registered: ‎07-14-2008
My Device: Not Specified

Re: Automatically inserted empty lines in multiline LabelFields / RichtTextFields on device

[ Edited ]

For me, the problem is most likely in the conversion/extraction from XML and/or some font issues related to the data that is being sent.

 

Logically if you extract a String from XML and display it, or create the String in your program and display, the LabelField should perform the same processing shouldn't it?  So if you are seeing different results, then it is because the data is different.

 

As a simple example, when you get data from a Web Service, you get it in bytes.  Typically people will supply the bytes in a String, and convert the bytes to the String using

String response = new String(bytes);

But most XML data is sent using UTF-8, so to get the correct String representation, you need the following:

String response = new String(bytes, "UTF-8");

 

I recommend that you dump out the data that you are displaying in the LabelField and confirm that it is what you expect. 

Please use plain text.
Developer
simon_hain
Posts: 15,846
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: Automatically inserted empty lines in multiline LabelFields / RichtTextFields on device

it would be important to analyze the data in the debugger.
i suspect that there are command characters in it, like '\n', which will not be visible if you just print the string to console etc.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Contributor
Musipoo
Posts: 41
Registered: ‎02-04-2013
My Device: Bold 9900
My Carrier: Vodafone

Re: Automatically inserted empty lines in multiline LabelFields / RichtTextFields on device

Thank you for your replies!

 

peter_strange, I think you're right, it must be an encoding problem, the setScreenTest() method shows the same data with the empty spaces meanwhile. It's really weird, that's the first time I noticed that problem.

 

I'm using KSOAP and I added the encodingStyle attribute "utf-8", but it doesn't help.

Unfortunately I don't habe the opportunity to debug, whether on the simulator nor on the real device (thanks to company policies..) So it's really hard to figure out the problem at the moment.. :Yawn:

Please use plain text.
Contributor
Musipoo
Posts: 41
Registered: ‎02-04-2013
My Device: Bold 9900
My Carrier: Vodafone

Re: Automatically inserted empty lines in multiline LabelFields / RichtTextFields on device

Okay, no matter which encodingStyle I choose, it still inserts some blank lines..

I've tried to manipulate the string afterwards but I'm  struggling with this too.. I used the replaceAll() method suggested in this post

 

http://supportforums.blackberry.com/t5/Java-Development/String-Manipulation-split-replace-replaceAll...

 

and called it with

 

String replacedString = replaceAll(array[clickedItem][5], "(?m)^[ \t]*\r?\n", ""); 

or

 

String replacedString = replaceAll(array[clickedItem][5], "\\s+", ""); 

 but none of it works.. Do you have any other ideas?

Please use plain text.
Developer
simon_hain
Posts: 15,846
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: Automatically inserted empty lines in multiline LabelFields / RichtTextFields on device

i would suggest that you find out what the characters you want to remove actually are.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.