Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
571 views
in Technique[技术] by (71.8m points)

sqlite - New Line character not displaying properly in textView Android

I know that if you do something like

myTextView.setText("This is on first line 
 This is on second line");

Then it will display properly like this:

This is on first line
This is on second line

When I store that string in a database and then set it to the view it displays as such:

This is on first line This is on second line

Here is the line of code I use to extract the string from the database:

factView.setText(factsCursor.getString(MyDBAdapter.FACT_COLUMN));

I simply populate the database from a text file where each line is a new entry into the table so a line would look like this "This is on first line This is on second line" and it is stored as text.

Is there a reason that it isn't displaying the characters properly? It must be something to do with the string being in the database. Any suggestions?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I found this question Austyn Mahoney's answer is correct but here's a little help:

   private String unescape(String description) {
    return description.replaceAll("\\n", "\
");
}

description being the string coming out of your SQLite DB


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...