Spinner不显示UTF-8字符

时间:2011-08-23 09:57:47

标签: android utf-8 spinner

我需要帮助我的纺纱工具。

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);

List调用类[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?

任何帮助都将不胜感激。

感谢; 拉蒙

1 个答案:

答案 0 :(得分:1)

您的网址声明了内容类型:

Content-Type: text/html; charset=iso-8859-1

所以你的读者应该

new InputStreamReader(isCountry, "ISO-8859-1")

更好的是,通过使用HttpClient而不是URLConnection,您可以获得内容类型:http://developer.android.com/reference/org/apache/http/HttpEntity.html#getContentType%28%29