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));
Related
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 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))
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'm writing an android application and I have issue with edit text.
When the user adds text with accent (sp: "Nous sommes en été");
The string isn't correct. It convert my accent symbole to utf-8 I guess.
How can I deal with it ?
ps: my application is a french app and I really need to use accent.
MY CODE :
String description = ((EditText) findViewById(id.description)).getText().toString();
Log.i("UTF8",description.toString());
description = description.replace("\n", "");
Log.i("UTF8",description.toString());
There shouldn't be a problem. String representations are UTF-16 [1] in java / android. I tried the following code on android and got it to work fine. The accented é displays correctly.
EditText findViewById =(EditText) findViewById(R.id.test_text);
findViewById.setText("École. Nous sommes en été");
Editable text = findViewById.getText();
Log.d(TAG, text.toString());
You know that the first parameter in your Log.i() code is a tag right ? Log.i() does not accept encoding type as a parameter. Can you post what those statements print ?
[1] - http://docs.oracle.com/javase/7/docs/api/java/lang/String.html
I am developing the application which consists of AutoCompleteTextView,here is my problem,How I can upper case the letters entering in AutoCompleteTextView.
I Don't want in xml: android:capitalize="characters"
I want to declare in Java code.
You can try like this..In your text watcher in ontextchanged change the text to upper case..and check if the new string in edittext is the old string which you converted to upper case...in order to avoid stackoverflow error..
String upper = mytextview.getText().toString().toUpperCase()
mytextview.setText(upper);
Try this in your code there are some other flags also which you can check and try.
tv.setInputType(InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS);