Spinner 不显示 UTF-8 字符
我的旋转器需要帮助。
Spinner 配置为以下代码...
List<String> lCountries = (Arrays.asList(Countries().split(";")));
CharSequence[] csCountries = lCountries.toArray(new CharSequence[lCountries.size()]);
final Spinner sCountry = (Spinner) findViewById(R.id.country);
ArrayAdapter<CharSequence> aCountry = new ArrayAdapter<CharSequence>(this, android.R.layout.simple_spinner_item, csCountries);
aCountry.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
sCountry.setAdapter(aCountry);
列表调用类 [Countries()
],这就是代码...
URL requestURL = new URL("http://www.merso.eu/phone/xml/Country.php");
URLConnection connection = requestURL.openConnection();
InputStream isCountry = connection.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(isCountry, "UTF-8"));
StringBuilder sbCountry = new StringBuilder();
String line;
sbCountry.append("Select a Country;");
while ((line = reader.readLine()) != null) {
sbCountry.append(line);
}
Countries = sbCountry.toString();
我已将 UTF8 更改为所有可能的更改 utf-8, utf8、UTF-8、UTF8 什么都没有。
我知道来自服务器的列表没问题,因为它可以在任何浏览器上运行,并且返回带有 UTF-8 字符的列表。
我缺少什么?我必须在其他地方输入 UTF-8 吗?
任何帮助将不胜感激。
谢谢; 拉蒙
I need help with my spinners.
The Spinner is configured with the following code...
List<String> lCountries = (Arrays.asList(Countries().split(";")));
CharSequence[] csCountries = lCountries.toArray(new CharSequence[lCountries.size()]);
final Spinner sCountry = (Spinner) findViewById(R.id.country);
ArrayAdapter<CharSequence> aCountry = new ArrayAdapter<CharSequence>(this, android.R.layout.simple_spinner_item, csCountries);
aCountry.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
sCountry.setAdapter(aCountry);
The List calls the class [Countries()
] and this is the code....
URL requestURL = new URL("http://www.merso.eu/phone/xml/Country.php");
URLConnection connection = requestURL.openConnection();
InputStream isCountry = connection.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(isCountry, "UTF-8"));
StringBuilder sbCountry = new StringBuilder();
String line;
sbCountry.append("Select a Country;");
while ((line = reader.readLine()) != null) {
sbCountry.append(line);
}
Countries = sbCountry.toString();
I have changed the UTF8 to all possible alterations utf-8, utf8, UTF-8, UTF8 and nothing at all.
I knwow the list from the server is OK, as it can be run on any browser and it returns the list with UTF-8 characters.
What am I missing? Do I have to type UTF-8 somewhere else?
Any help would be appreciated.
Thanks;
Ramón
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的 url 声明了内容类型:
因此您的阅读器应该
更好,通过使用 HttpClient 而不是 URLConnection,您可以获得内容类型: http://developer.android.com/reference/org/apache/http/HttpEntity.html#getContentType%28%29
Your url declares a content-type :
so your reader should be
Better even, by using HttpClient instead of URLConnection, you can get the content type : http://developer.android.com/reference/org/apache/http/HttpEntity.html#getContentType%28%29