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>
Sepehr Behroozi
  • 1,780
  • 1
  • 17
  • 32

1 Answers1

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

Community
  • 1
  • 1
Darpan
  • 5,623
  • 3
  • 48
  • 80