字符串编码TextView.setText() [英] String Encoding TextView.setText()

查看:142
本文介绍了字符串编码TextView.setText()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在TextView中设置文本时,无法正确解释字符ù。这是我的代码:

while setting text in a TextView, the character 'ù' isn't correctly interpreted. 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

推荐答案

您已使用 ISO-8859-1 ,但是Java默认使用 UTF-8 ,因此在创建字符串时定义字符集

You have used "ISO-8859-1" but java uses by default UTF-8 so either define the charset while creating string

来自文档


案例映射基于由
字符类指定的Unicode标准版本,并且一个String表示UTF-16格式的字符串

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

so

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

或根本不使用它

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

这篇关于字符串编码TextView.setText()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆