简体   繁体   中英

How to show heart sign in android using Html.fromHtml

In my app I am fetching some data from the server, the data might contain some unicode characters like heart, etc.

Now I can show a black heart symbol using unicode format, this way

String str = "\u2764";//unicode character for black heart
TextView txtv = (TextView)findViewById(R.id.txtv);
txtv.setText(txtv.getText()+str);

but I'm setting the text like this:

holder.txt_cardDesc.setText(Html.fromHtml(cardsDataClass.getCarddesc()));

cardsDataClass.getCarddesc() returns "âÂÂ¥All is changing soon, Christmas coming and we pray to God for all to..."

and I'm supposed to get 'âÂÂ¥' as the heart symbol from the service.

how to show this special character in unicode format, or in heart symbol as it is required?

which format is this text showing?? Is it HTML/XML format or Klingonese character, I don't have any idea about this.

How to show the heart sign using Html.fromHtml in android?


EDIT: From the service I may get different special characters like " ' " or "&" but what I'm getting is "’" instead of " ' ", "âÂÂ¥" instead of " ♥ "

Is there any way to check all the text and show the correct special character in android?


EDIT 2: Can anyone tell me how to show a heart symbol and apostrophe at their position from this string

String desc = "âÂÂ¥heart icon check, €™ apostrophe check";

i have already used all these procedures:

byte[] bytes = desc.getBytes("UTF-8");              
String s2 = new String(bytes, "UTF-8"); // Charset with which bytes were encoded
txtv.setText(s2);

final String s2 = new String(desc.getBytes(), "UTF-8");
txtv.setText(s2);

String s2 = URLDecoder.decode(desc, "UTF-8");
txtv.setText(s2);

byte[] data = desc.getBytes("UTF-8");
String base64 = Base64.encodeToString(data, Base64.DEFAULT);
byte[] data1 = Base64.decode(base64, Base64.DEFAULT);
String text = new String(data1, "UTF-8");
txtv.setText(text);

but none of them are working, how to show UTF-8 text format in its actual format

Thanks

You maybe confused with Java Character & Android Character.

let your cardsDataClass.getCarddesc() returns:

"\❤All is changing soon, Christmas coming and we pray to God for all to..."

and the heart should be shown just fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM