Reputation: 89
I am getting data from xml for line break in following format; line1 \n line2.but on setting this string in textview its displaying line1 \n line2 intead of; line1 line2. if i hardcode the the value in textview its giving correct result but getting data from xml is not showing properly...
Upvotes: 1
Views: 5121
Reputation: 19
Both previous answers were almost there. The BR tag doesn't do so well with Android. However, \n
works if you wrap it in a CDATA element as shown below.
In your strings.xml values file add this:
<string name="sample_string"><![CDATA[some test line 1 \nsome test line 2]]></string>`
Upvotes: 0
Reputation: 21561
If you plan as using the string as HTML, you can use <br />
for a line break(<br />
)
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="title">Hello<br />World!</string>
</resources>
(or)
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="title">Hello\nWorld!</string>
</resources>
Upvotes: 2
Reputation: 1739
<string name="sample_string"><![CDATA[some test line 1 <br />some test line 2]]></string>
so wrap in CDATA is necessary and breaks added inside as html tags
Upvotes: 4