1

I have a string array and was trying to style certain parts of the text with tags like < b>, < i>, ... but it doesn't work. The array looks like this:

<resources>
    <array name="hour1">                             
            <item>blabla\n<b>blabla</b></item>
</array>

The text is displayed in the textview like this:

tTitel.setText(Html.fromHtml(Text[ii]));

I tried it without Html.fromHtml too but this had no effect. The styling tags do work if i use them directly in the code, like:

tTitel.setText(Html.fromHtml("blabla<b>blabla</b>");

Any ideas how to style the text in an array??

Cheers, Chris

2
  • What exactly is Text[ii] in the above line? Have you tried accessing it directly via R.java? Commented Feb 15, 2010 at 16:13
  • It's an array that contains one item of the string array "hour1". I need that because I split the text and then do different things with it based on what pattern made it split. Commented Feb 15, 2010 at 17:34

1 Answer 1

3

You need to escape your HTML tags when they are included in an XML resource document. Instead of:

<b>

use:

&lt;b&gt;

At least, that works for ordinary string resources. I assume it works for string arrays.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks a lot! This works perfectly fine! Using < b> in ordinary string resources without escaping it works for me, too. That's why I hadn't thought of that. Thanks again!
Really? That's interesting. The last time I tried embedding un-escaped HTML in string resources, it failed. I haven't tried in over a year, though, so perhaps that was fixed and the fix didn't ripple through to string-array resources.

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.