I am getting some Unicode string(emoji icons) from server in json string format.
My problem is strange and I am trying for last two days to resolve this issue. When I parse json and store all the Unicode string in an ArrayList<String> and try to set the text on TextView by getting value from the same ArrayList then it shows Unicode characters as :
Ghcghchgc\ud83d\ude03\ud83d\ude03fyju\ud83d\ude0c6\u20e3
and when the same string I set on textview by passing static value as :
textview.settext("Ghcghchgc\ud83d\ude03\ud83d\ude03fyju\ud83d\ude0c6\u20e3")
then the textview is showing perfect emojis.
I am stuck at this point. Can anybody please help me to resolve this issue or tell me if I am doing something wrong.
This sounds like you want to unescape your string that you've got from JSON. If you don't mind adding a library, Apache Commons has a String.unescapeJava function which does what you need. If you don't want to add that library, see this answer.
This is what has worked for me ( Kotlin version ):
textView.text = String(Character.toChars(0x1F389))
Related
I had found an answer that we can use bullets in textview by adding u\2022 with the text.
Ref : https://stackoverflow.com/a/3429643/4919237
When i added this code through XML it displays fine in TextView
and When i try to display bullet through json it doesnt display bullet ,instead it displays the text u\2022 itself.
my receiving Json format is
{"description":"\\u2022first one\\n\\u2022second one edited\\n"}
please help me to reslove my problem.
At First , You can check Html.fromHtml & remove one \ .
Html.formHtml method takes an Html.TagHandler and an Html.ImageGetter
as arguments as well as the text to parse.
YourTextViewObj.setText(Html.fromHtml("Your String"));
FYI
Currently android seems support the following HTML tags to be rendered on TextView.
You can set text using Html.fromHtml like
textview.setText(Html.fromHtml(your description));
I'm new to android. I've created an EditText and if I assign the property android:text from xml code using a word with accents (I try with àèìòù) I see the text displayed correctly.
If I try to assign with string value edit_message, I get the unknown character symbol. This is my code:
EditText editText=(EditText)findViewById(R.id.edit_message);
editText.setText("àèìòù");
I think it's an encoding problem, but it seem strange.
The string shouldn't be UTF-8 by default?
Use HTML entity-codes via Html.fromHtml:
editText.setText(Html.fromHtml("àé ...");
A list of entity codes is available here:
http://symbolcodes.tlt.psu.edu/web/codehtml.html
You could use the method htmlEncode of the TextUtils class to automaticaly convert your input-text to an encoded-format:
string encodedText = TextUtils.htmlEncode("àèìòù");
editText.setText(Html.fromHtml(encodedText));
In my app I have a message which can be customised by the user and then displayed in the app.
If the user enters "£100" it is shown as "£100"?
I tried to use a font which contains this symbol but it didn't fix my problem.
Typeface font = Typeface.createFromAsset(getActivity().getAssets(), "arial_unicode.ttf");
alertTextView.setTypeface(font);
alertTextView.setText(message);
I tried to use *Arial Unicode MS, Verdana, Arial, Code2000... but the problem persits.
Any ideas?
Use the codes like \u00A3 (lira) or try to change the encoding of the string like this:
byte[] myByteArray = message.getBytes(Charsets.UTF_8);
String encodedMessage = new String(myByteArray, Charsets.UTF_8);
alertTextView.setText(encodedMessage);
I fixed my issue.
The problem was about the way how I fetch and format this data in my message variable.
As I sais in my comment above, I fetch this information from Json data through an API. At this point, the character convertor that I was using wasn't correct I had to change it from "iso-8859-1" to "utf-8" to be able to read correctly my currency symbol.
I am getting some strings from json. My string contains special characters like "æ" from Næstved an many more like "ø" from køkken. But When I set Text these strings to ant textview, I get my strings printed in unusual way.
Example: For køkken I get kø ;kken.
I think I need to encode or decode my string somewhere but where I don,t know.
Please help.
Thanks in advance
The displayed version of your string represents an HTML encoded entity. You might want to verify that it is not coming in this way in your JSON data, but in any case, to decode it you can use the StringEscapeUtils.unescapeHtml4 method from Apache Commons Lang:
final String escaped = "køkken";
System.out.println(StringEscapeUtils.unescapeHtml4(escaped));
Output:
køkken
Did you check out the Latin Coding for your characters? I know the Ash character can be coded with æ and will show up æ in the browser.
Here is the a list of codes
Hope this helps!
I have had a problem with formattings symbols shown on the image. I got help from this site and I used Html.fromHtml() and hope that it would use the formatting, the only thing it did was to remove the formatting symbol but not anything else like newline or so.
If I cant find a way to use the formatting I wonder if it is possible to add a "\n" everytime the symbol is shown. The thing is if I try to use a method like
(Ps the "[]" is used here instead of the real symbol cause I cant find out how to write it.
int nr=theTextString.indexOf("[]")
and then replace the text with
theTextString=theTextString.substring(0,nr)+ "\n" + theTextString.substring(nr);
but the problem is that the symbol is not represented as a character to look for the index at, not in any way I know of. Would really be thankful for help.
If [] crap character is only shown on the last chacter do this
Log.i("My String before:", theTextString);
theTextString = theTextString.substring(0, theTextString.length()-2);
Log.i("My String after:", theTextString);
Btw: [] <-- is not the same character (Infact, there are two characters) it is something else.
Solution: To encode the string
theTextString = URLDecoder.decode(theTextString, HTTP.UTF-8);