Bad result with encoding when Selecting arabic data from SQLite & android

一笑奈何 提交于 2019-12-12 05:42:00

问题


I have a problem with SQLite and android, I`m trying to select arabic data from the db, the db filled by the data outside android and i push it to android emulator.. the english text appears normaly but the arabic text appear in wrong way

the text appears like this img

so help me plz


回答1:


I checked with Arabic database with random text created via code:

db = openOrCreateDatabase("dictionary", MODE_PRIVATE, null);
db.execSQL("CREATE TABLE IF NOT EXISTS LIST(wlist varchar);");
db.execSQL("INSERT INTO LIST VALUES('صبالخير');"); 
db.execSQL("INSERT INTO LIST VALUES('صبا لخير');");  

Then I used following query with cursor to dynamically select text from database:

String q = "SELECT * FROM LIST";
Cursor c = db.rawQuery(q, null);
if(c.getCount() == 0)
  {
    setSuggestions(list, true, true);
  }
else{
  int i=0;
  c.moveToFirst();
     do {
         String cm = c.getString(c.getColumnIndex("wlist")); 
                      list.add(cm);
                      i++;
        } while (c.moveToNext() && i<30);      

The result is as follows:


Arabic text is shown. So, check your existing database with a SQLite Database Browser if Arabic data is in correct form there.

来源:https://stackoverflow.com/questions/10518409/bad-result-with-encoding-when-selecting-arabic-data-from-sqlite-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!