SH_V95 SH_V95 - 5 months ago 28
Android Question

Android printing Emojis using string

I have a variable (emoji) that contains a string

\ud83d\ude03
which I have got from parsing an xml. They are emoticon encodings. The problem is when I try to print them in the following way :

editText.setText(emoji)


the output is
\ud83d\ude03


However when I do this :

editText.setText("\ud83d\ude03")


the output is smiley. Is there any work around to this? I think the problem is that my backslash is getting escaped. I cant change the xml files and thus I've tried converting the strings in java itself with no avail.

Answer

This code:

String smiley = "\ud83d\ude03";
EditText et = (EditText) findViewById(R.id.editText);
et.setText(smiley);

TextView tv = (TextView) findViewById(R.id.textView);
tv.setText(smiley);

Layout file:

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="New Text"
    android:id="@+id/textView"
    android:layout_marginTop="150dp"
    android:layout_marginLeft="50dp"/>


<EditText
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/editText"
    android:layout_below="@+id/textView"
    android:layout_alignLeft="@+id/textView"
    android:layout_alignStart="@+id/textView"/>

It works as you see. You error must be in emoji variable.

Solution