0

I am having Problems filling my TextView. I have an HTML String that needs to be converted from HTML to String and the replace some characters. Problem is: I can convert it directly with: TextView.setText(Html.fromHtml(sampleText);

But I need to alter the converted sampleText before giving it to the TextView.

E.g.:

String sampleText = "<b>Some Text</b>"
newSampleText = Html.fromHtml(sampleText);
newSampleText.replace(char1, char2);
TextView.setText(newSampletext);

Does anyone know how to convert the HTML saved inside the String?

2
  • 1
    Perhaps you should just sampleText.replace(char, char); before calling TextView.setText(Html.fromHtml(sampleText)). Commented Sep 2, 2015 at 10:01
  • Yeah, I know, Problem is, that I want to replace <li> with a break. but Html.fromHtml deletes all spans. And Replacing <li> with "\n" before conversion does not work for me. Commented Sep 2, 2015 at 10:03

2 Answers 2

4

if you don't need formatting, use Html.fromHtml(sampleText).toString()

otherwise, you need to extract text from html with jsoup to find and change text like here

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

Comments

0

please try this one:

You need to use Html.fromHtml() to use HTML in your XML Strings. Simply referencing a String with HTML in your layout XML will not work.

DEMO

Try use This version of setText and use SPANNABLE buffer type

DEMO1

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.