Reputation: 4307
I read data from an utf8 database then display it in a listview. but there are words in the database containing è é à á letters when I get the xml manually in the browser it shows up perfect
but in the listview it shows question marks instead
how can I set the character set to utf8 for my listview? or is there another way around?
Upvotes: 4
Views: 8695
Reputation: 197
Since I am developing an application that uses foreign language words (including French) I will share what worked for me. In my application, each character with a special accent was showing as a black diamond with a white question mark. I have a copy of my database on the laptop and use mainly Excel to load data into it (I create CSV files which I then import through DB Browser for SQLite
). In my CSV files I could see all the accents correctly, but after I imported them to the database, there were black diamonds everywhere. I tried both encoding, decoding, using Html.fromHtml etc. The only thing that worked for me was to copy a word with special character manually and paste it in the database (with the use of the program). This worked without any problems and now my database contains no black diamonds. The only problem - since it's a manual job it takes time, a lot of time.
Upvotes: 0
Reputation: 3361
Let response be the object returned from your server. Do the folling:
response = Utilities.encodedToUTF8(response);
public static String encodedToUTF8(String response) {
try {
response = new String(response.getBytes("ISO-8859-1"), "UTF-8");
} catch (UnsupportedEncodingException e) {
Log.e(TAG, "Error: " + e.getMessage());
}
return response;
}
Upvotes: 0
Reputation: 11
I had this same problem. Make sure you're not using StringBufferInputStream (which is deprecated). That method causes this issue.
Upvotes: 1
Reputation: 38168
I had this problem once.
You should completely remove your database. I am pretty sure you did the right things to your data with iconv and the pragma in sqlite now. So the problem is that your database in your package is the old version. So clean the project in eclipse, uninstall your app completely from android by removing the database before uninstall, change sqlite installer version code (DatabaseHelper) and relaunch.
Hope it helps, Stéphane
Upvotes: 0
Reputation: 16363
That's really weird, since Android works with UTF-8... In my case I'm using UTF-8 encoded resources (Italian, German, Russian, Chinese), files and so on - and everything works.
There are 3 options why french accented characters shown as "?" marks:
Charset
Upvotes: 3
Reputation: 38168
You should double check your file encoding on your computer. Does your system use latin-1 (iso-8859-1) or utf-8 ?
Accents can look good in a latin-1 encoded file declaring a xmlns in utf-8 but indeed there not really stored in utf-8.
Salutations, Stéphane
Upvotes: 1