New Line character \n not displaying properly in textView Android

前端 未结 5 1701
星月不相逢
星月不相逢 2020-12-02 17:53

I know that if you do something like

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

Then it will display properl

5条回答
  •  星月不相逢
    2020-12-02 18:23

    As Falmarri said in his comment, your string is being escaped when it is put into the database. You could try and unescape the string by calling String s = unescape(stringFromDatabase) before you place it in your TextView.

    As a side note, make sure you are using DatabaseUtils.sqlEscapeString() on any kind of data that is from the user or an unknown changeable source when inserting data into the database. This will protect you from errors and SQL Injection.

提交回复
热议问题