I am parsing some unicodes
from json
to my android
app, the api gives unicodes
of icons like \ue600
, When I add this unicode directly into the textview
like textview.setText("\ue600");
it gives right icon on the textview
. but when i parse this unicode from json
api
& then I setText
that unicode
it just displays \ue600
on textview
.
How I parse or convert these strings into unicodes
to get the icons in textview
.
Thanks
Convert your unicode
into this format 
& then use like this in your textview
textview.setText(Html.fromHtml(your_unicode_here));
It should work.
StringEscapeUtils does most of the work, however it only goes up to HTML4. For characters not covered you can make your own class and add as needed. Here is a sample class
public class HTMLDecoder {
public static String decodeHTML(String html) {
String out = StringEscapeUtils.unescapeHtml4(html);
out = out.replaceAll("®", "®");
out = out.replaceAll("â\u0084¢", "™");
return out;
}
}
Add to build.bradle
compile 'org.apache.commons:commons-lang3:3.0'
Following works fine for me.
String unicode = "\u0048\u0065\u006C\u006C\u006F";
String Title = StringEscapeUtils.unescapeJava(unicode);
System.out.println(Title);
and add dependency : compile 'commons-lang:commons-lang:2.6'
in your build.gradle
file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With