0

I'm using cwac-richedit librar in my project
user write some text in it and app will save user input as HTML content

my problem is when i want to show saved content to user, it displays as HTML content. i tried this :

Spanned description = Html.fromHtml(stepContent);
rtxtStepDescription.setText(description);

and it looks like this

Screenshot

EDITED: this is what user writes in edittext:
enter image description here
app saves this content with Html.toHtml(rtxtStepDescription.getEditableText())

after that, next time i open my app this is what app loads:
<p dir="rtl"><u>&#1587;&#1604;&#1575;&#1605;</u><br> &#1605;&#1578;&#1606; <i>&#1570;&#1586;&#1605;&#1575;&#1740;&#1588;&#1740;</i> &#1576;&#1585;&#1575;&#1740; <b>&#1587;&#1608;&#1575;&#1604;</b></p>

6
  • Hey, post the value of stepContent so that I could try it here if I could get it working Commented Oct 9, 2014 at 10:42
  • i will add an example in couple of minutes Commented Oct 9, 2014 at 11:09
  • @Darpan Here it is an example of user input Commented Oct 9, 2014 at 11:17
  • "this is what the app loads" -- are you saying that is what you are passing into Html.fromHtml()? Or are you saying that is what you are getting out of Html.fromHtml()? Commented Oct 9, 2014 at 11:33
  • This is what is passed to Html.fromHtml () and what getting out of it! And I don't know why Commented Oct 9, 2014 at 11:36

1 Answer 1

1

Figured it out. These are HTML entities, See one convertor online here.

use Apache StringEscapeUtils from Apache commons lang:

import org.apache.commons.lang.StringEscapeUtils;
...
String withCharacters = StringEscapeUtils.unescapeHtml(yourString);

JavaDoc says:

Unescapes a string containing entity escapes to a string containing the actual Unicode characters corresponding to the escapes. Supports HTML 4.0 entities.

For example, the string "&lt;Fran&ccedil;ais&gt;" will become "<Français>"

If an entity is unrecognized, it is left alone, and inserted verbatim into the result string. e.g. "&gt;&zzzz;x" will become ">&zzzz;x".

as described in answer here

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

1 Comment

it worked because, because of the reasons I mentioned in first two lines :P

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.