2

If I have this string array:

<string-array name="htmlstrings">
    <item><i>blah<br />blah</i></item>
    <item><b>1st line<br />2nd line</b></item>
</string-array>    

And I get it and set it as text:

String[] htmlstrings = getResources().getStringArray(R.array.htmlstrings);
textV.setText(Html.fromHtml(htmlstrings[1]));

As output I get:

1st line2nd line

But I want to get

1st line

2nd line

For regular strings (not string-array) I know I can get and display HTML with getText() like:

textV.setText(getText(R.string.onehtmlstring));

but I don't know what's the getText() equivalent for a string-array.

1
  • I used the line break just to illustrate the problem. What I need is HTML formatting, including bold, italic and font color like I can do with string resources (but not string-array members) Commented May 1, 2014 at 5:44

3 Answers 3

2

Use getTextArray() to make a CharSequence array, and set your TextView using that array.

CharSequence[] htmlchars = getResources().getTextArray(R.array.htmlstrings);
textV.setText(htmlchars[1]);
Sign up to request clarification or add additional context in comments.

Comments

1

Have you try below code:-

Spanned sp = Html.fromHtml( getString(R.string.htmlsource));
tv.setText(sp);

or

Set TextView text from html-formatted string resource in XML

4 Comments

I can't use getString() because it's a string-array. I tried using Spanned sp = Html.fromHtml(htmlstrings[1]); textV.setText(sp); but there's no difference, it ignores HTML in the string.
Enclosing the string in <![CDATA[]> works great, thanks
@TimSim is link is use full to you ?
Yup, CDATA saves the day
1

Try with CDATA attribute:

<string-array name="channel_link">
    <item><![CDATA[https://news.google.com/news/feeds?pz=1&cf=all&ned=in&hl=en&output=rss]]></item>
</string-array>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.