HelmiB
HelmiB

Reputation: 12333

Add new line `\n' on TextView won't work

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

Upvotes: 1

Views: 5497

Answers (3)

HelmiB
HelmiB

Reputation: 12333

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"));

    }

Upvotes: 3

kabuko
kabuko

Reputation: 36312

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

Upvotes: 0

nithinreddy
nithinreddy

Reputation: 6197

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?

Upvotes: 0

Related Questions