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.

TimSim
  • 3,936
  • 7
  • 46
  • 83
  • 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) – TimSim May 01 '14 at 05:44

3 Answers3

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]);
JerabekJakub
  • 5,268
  • 4
  • 26
  • 33
paralith
  • 86
  • 4
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

Community
  • 1
  • 1
duggu
  • 37,851
  • 12
  • 116
  • 113
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>
Sujith Thankachan
  • 3,508
  • 2
  • 20
  • 25
Rahul Devanavar
  • 3,917
  • 4
  • 32
  • 61