Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a long text with many paragraphs in string.xml in android

When I added many paragraphs between

<string name="bbb"> ...... </string>

it showed me following error.

[2014-12-22 14:54:55 - Inspiration] Her father rescued her from the heartless husband  and she was back her to the 
[2014-12-22 14:54:55 - Inspiration] G:\adt-bundle-windows-x86_64-20140702\workspace\Inspiration\res\layout\activity_women.xml:11: error: Error: No resource found that matches the given name (at 'text' with value '@string/Women1').
like image 811
Lakshmi16 Avatar asked Dec 22 '14 09:12

Lakshmi16


People also ask

How do I add spaces to text in XML?

As already mentioned the correct way to have a space in an XML file is by using \u0020 which is the unicode character for a space.

How do I add a new line to a string in XML?

typical string with escape sequence like '\n' can't be used, because this string has no special meaning in XML. Instead of you need to use hexadecimal escaped character: &#10; for newline or &#13; for carriage return.

What is the use of string XML file in Android?

A string resource provides text strings for your application with optional text styling and formatting. There are three types of resources that can provide your application with strings: String. XML resource that provides a single string.


2 Answers

Try this

 <string name="Your string name" > This is your string.

       This is the second line of your string.\n\n Third line of your string.</string>

This will result in the following on your TextView:

This is your string.

This is the second line of your string.

Third line of your string.
like image 87
januprasad Avatar answered Nov 14 '22 21:11

januprasad


You can add the long string to /res/values/strings.xml, as it appears you've done.

You can separate paragraphs with the \n.

You will need to use Unicode codes for special characters like backslash, etc.. See this answer.

Yes, was just going to add what's in the other answer: The other trick is to use the CDATA trick:

<![CDATA[Foo Bar <a href="foo?id=%s">baz</a> is cool]]>

See this answer for more on that.

like image 38
JASON G PETERSON Avatar answered Nov 14 '22 22:11

JASON G PETERSON