1

I don't know why it doens't work. My TextView already set lines=6. String is set in code, like this :

address.setText((String) bundle.get("address"));

Above code still display \n as String not new line. bundle.get("address") is retrieved from .dat which is "line1\nline2" file store in asset But when i try this :

address.setText("line1\nline2");

this code works fine.

Any idea what gone wrong here? Thanks in advance

HelmiB
  • 12,303
  • 5
  • 41
  • 68

3 Answers3

3

It's not really an answer i'm looking for, but i managed to do a bit of code to replace \n inside String (read from text file) to \n in code. here's my solution.

String seperator = "\n";  
String []tempText = a.split(seperator);

if (a.contains(seperator)){
        String b= "";
        for (String c : tempText)
            b +=c+"\n";
        b= b.substring(0, b.length()-2);
        address.setText(b);

    }else{
        address.setText((String) bundle.get("address"));

    }
HelmiB
  • 12,303
  • 5
  • 41
  • 68
0

Why don't you try giving an escape sequence for the . Please replace \n with \\n in the asset file, and see if it shows rightly now?

nithinreddy
  • 6,167
  • 4
  • 38
  • 44
0

You probably have the slash encoded in your .dat file. Make sure that it's actually a newline character there.

kabuko
  • 36,028
  • 10
  • 80
  • 93
  • I'm not quite understand what you mean. it displays : `line1\nline2` but display as it is, no separator line – HelmiB Mar 07 '12 at 03:00
  • What I mean is that if in your .dat file you have literally: line1\nline2, then that's what will come out (a slash then an n). \n is a special convention in Java (and some other languages) to represent a newline character. See [this question](http://stackoverflow.com/questions/3537706/howto-unescape-a-java-string-literal-in-java) for more. – kabuko Mar 07 '12 at 03:54