Reputation: 465
I'm getting some data from an SQLite database. The data consists of text and some tabs (\t) and newline (\n) elements. When I print the string from a file, everything is shown correctly, but if I get my string from the database, the newline and tabs are shown in text.
For example:
This is my first row\tText afterTab\nThis is my second row\tText after second tab
Here is my sourcecode:
java:
textfieldAntwort = (TextView) findViewById(R.id.textViewAntwort);
textfieldAntwort.setText(frageundantwort.getAntwort());
xml:
<TextView
android:id="@+id/textViewAntwort"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textViewFrage"
android:layout_below="@+id/ima_frage"
android:layout_marginTop="20dp"
android:text="@string/txt_answer" />
Upvotes: 2
Views: 984
Reputation: 3476
You need to unescape your string
String s = unescape(stringFromDatabase)
before you place it in your TextView.
private String unescape(String description) {
return description.replaceAll("\\\\n", "\\\n").replaceAll("\\\\t", "\\\t");
}
Source: New Line character \n not displaying properly in textView Android
Upvotes: 4