Spinner 不显示 UTF-8 字符

发布于 2024-12-01 02:31:44 字数 1333 浏览 0 评论 0原文

我的旋转器需要帮助。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一曲爱恨情仇 2024-12-08 02:31:44

您的 url 声明了内容类型:

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

Your url declares a content-type :

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

so your reader should be

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文