简体   繁体   English

字符串编码TextView.setText()

[英]String Encoding TextView.setText()

while setting text in a TextView, the character 'ù' isn't correctly interpreted. 在TextView中设置文本时,无法正确解释字符'ù'。 This is my code: 这是我的代码:

TextView tv = new TextView(context);
String s;
byte[] bytes;
s = "dgseùeT41ù";
bytes = s.getBytes("ISO-8859-1");
tv.setText(new String(bytes));

I don't know where I'm failing. 我不知道我要去哪里。 Thank you for support 谢谢你的支持

You have used "ISO-8859-1" but java uses by default UTF-8 so either define the charset while creating string 您已使用"ISO-8859-1"但Java默认使用UTF-8因此在创建字符串时定义字符集

From docs 来自文档

Case mapping is based on the Unicode Standard version specified by the Character class and A String represents a string in the UTF-16 format 大小写映射基于Character类指定的Unicode标准版本,并且String表示UTF-16格式的字符串

so 所以

bytes = s.getBytes("ISO-8859-1");
tv.setText(new String(bytes,"ISO-8859-1"));

or don't use it at all 或根本不使用它

bytes = s.getBytes();
tv.setText(new String(bytes));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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