Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7949423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:59:39+00:00 2026-06-04T01:59:39+00:00

I have a string resource called foo. It may be a simple string… or

  • 0

I have a string resource called “foo”. It may be a simple string… or it may contain HTML. This may change over time: I should be able to box it up as at least a SpannableString immediately upon reading whether it’s HTML or not (but how??)

I want to get that raw CharSequence and first be able to display it as-is (the exact characters, not Android’s “interpretation” of it). Right now I can’t do that… toString() decides to rip out the parts it doesn’t think I want to see.

I’d then like to be able to create a SpannableString from this and other Strings or SpannableStrings via concatenation using some method (none of the normal ones work). I’d like to then use that SpannableString to display the HTML-formatted text in a TextView.

This shouldn’t be difficult, but clearly I’m not doing it right (there’s very little info out there about this that I’ve found so far). Surely there is a way to accurately interconvert between between Strings, SpannedStrings and even Spannablestrings, without losing the markups along the way?

Note that I’ve already played with the somewhat broken Linkify, but I want better control over the process (no dangling unformatted “/”s, proper hrefs, etc.) I can get this all to work IF I stay in HTML at all steps, though I can’t concatenate anything.

Edit 1: I’ve learned I can use the following to always ensure I get my raw string (instead of whatever Android decides it thinks the CharSequence really is). Nice… now, how to coax this into a SpannableString?

<string name="foo"><![CDATA[
    <b>Some bold</b>
]]>
</string>

Edit 2: Not sure why this didn’t work earlier, but… if foo1 and foo2 are strings marked up as above (as CDATA), then one can apparently do this:

String foo1 = (String)getResources().getText(R.string.foo1);
String foo2 = (String)getResources().getText(R.string.foo2);
SpannedString bar = new SpannedString(Html.fromHtml(foo1+foo2));

Curious: is there a more straightforward solution than this? Is this CDATA business actually necessary? It seems convoluted (but not as convoluted as never quite knowing what the resource type will be… String, Spannable, etc.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T01:59:40+00:00Added an answer on June 4, 2026 at 1:59 am

    It appears there isn’t a more straightforward way to accomplish this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

It basically comes down to this. I have a string called $name. $name usually
I have problem to make work a resource file. This is my simple code
I have string like this: G:\Projects\TestApp\TestWeb\Files\Upload\file.jpg How can I remove all text before Files
i have string stored in python variables, and i am outputting a html that
I have string looking like this: 'Toy Story..(II) (1995)' I want to split the
I have: String uri = @drawable/myresource.png; How can I load that in ImageView? this.setImageDrawable?
I have a handler that shows user a message (this is called by jquery
I have a variable called $result which should store all the results from my
How can I set the resource string in javascript? I have a resource file
I have created a series of resource (resx) files to hold language specific string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.