Spinner is not displaying UTF-8 characters
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 char开发者_如何学JAVAacters.
What am I missing? Do I have to type UTF-8 somewhere else?
Any help would be appreciated.
Thanks; Ramón
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
精彩评论