0

I receive text from a server which can contain \n to indicate a necessary line break. When I display this text in a TextView, the system will not do the line break, but simply treat \n as normal text. How can I tell android to interprete this as a line break?

michaelsmith
  • 1,011
  • 1
  • 16
  • 35

1 Answers1

0

You'd have to read the file as a byte[] of characters and handle it this way. Specifically depending on the content, if its a TextView, you may need to change how the setText() would work. Meaning you'd have to create your own class that extends the TextView class.

In this class you would specify your logic rules based on the content that is being added to this particular View.

JoxTraex
  • 13,423
  • 6
  • 32
  • 45
  • I have all processing in place to format my TextView, so no worries on that side. The only thing I couldnt find out yet how to do is the problem with the line break. In IOS, it is sufficient to do a stringByReplacingOccurrencesOfString:@"\\n" withString:@"\n"] Isnt there anything just as easy in android? – michaelsmith Jan 21 '12 at 13:42
  • Java has code that allows you to do this. If you look up the String class, you'll find what you're looking for. This is chase functionality, not android specific. – JoxTraex Jan 21 '12 at 13:44
  • I know how to do that in Java ( myString.replace("\\n", "\n"); )but this does not impress the TextView. It simply displays the \n as text and not as line break – michaelsmith Jan 21 '12 at 13:58
  • you may have to convert it to a string literal then. – JoxTraex Jan 21 '12 at 13:59