03-26-2013 07:00 AM - edited 03-26-2013 07:03 AM
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]); text.setFont(subtitleFont); text.setMargin(5,0,5,10); add(text);
03-26-2013 07:29 AM
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.
03-26-2013 08:35 AM
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..
03-26-2013 09:09 AM - edited 03-26-2013 10:53 AM
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.
03-26-2013 09:49 AM
03-26-2013 10:22 AM
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..
03-27-2013 07:42 AM
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
and called it with
String replacedString = replaceAll(array[clickedItem], "(?m)^[ \t]*\r?\n", "");
String replacedString = replaceAll(array[clickedItem], "\\s+", "");
but none of it works.. Do you have any other ideas?
03-27-2013 08:04 AM