2013-12-23 3 views
1

데이터베이스 SQLite로 Android 앱을 만들고 있습니다.
아랍어 텍스트를 데이터베이스에 저장하려고했습니다. 1과 2는 아랍어 텍스트를 삽입하고 4는 아랍어 텍스트에서 유니 코드를 삽입했습니다. 데이터베이스에서 데이터를 얻을 내 코드입니다
enter image description hereSQLite에 아랍어 텍스트를 저장하고 Android 앱에서 읽을 수있는 가장 좋은 방법은 무엇입니까

String textDoa = ""; 
try { 
    textDoa = new String(cursor.getString(cursor.getColumnIndex("DOA_ARAB")).getBytes(), "UTF-8"); 
} catch (UnsupportedEncodingException e) { 
    e.printStackTrace(); 
} 

doaDetail.setDoaArab(Html.fromHtml(textDoa).toString()); 

.
그리고 this

TextView textDoa = new TextView(this); 
try{ 
    textDoa.setTypeface(tf); 
    textDoa.setText(ArabicUtilities.reshape(doa.getDoaArab())); 
    //textDoa.setText(doa.getDoaArab()); 
    textDoa.setTextSize(17f); 
} catch(Exception ex){ 
    textDoa.setText("font cannot load: "+ ex.toString()); 
} 

에서 ArabicReshaper를 사용하지만 결과는 내가 기대했던 다르다.

1의 경우 텍스트 뷰가 나타납니다

그리고 4 . الْحَمْد٠لÙلَّه٠الَّذÙÙŠ أَحْيَاناَ بَعْدَ مَا أَمَاتَنَا ÙˆÙŽØ¥Ùلَيْه٠النّÙØ´ÙوْرÙ는 데이터베이스로 등 표시, 아랍어 텍스트를 변경하지 않았다.

이 문제를 해결하는 데 도움을주십시오.

답변

0

많은 사람들이이 문제를 겪었으므로 UTF-8을 사용하여 텍스트 파일로 저장하고 SQL에 저장하는 것이 좋습니다. 그들을 검색 할 수 있습니다. 큰 대화가 필요하지 않았습니다.

및 텍스트 파일을 읽는 방법을 모르는 경우. 인스턴스 SDCard에 대한

//Find the directory for the SD Card using the API 
//*Don't* hardcode "/sdcard" 
File sdcard = Environment.getExternalStorageDirectory(); 

//Get the text file 
File file = new File(sdcard,"file.txt"); 

//Read text from file 
StringBuilder text = new StringBuilder(); 

try { 
    BufferedReader br = new BufferedReader(new FileReader(file)); 
    String line; 

    while ((line = br.readLine()) != null) { 
     text.append(line); 
     text.append('\n'); 
    } 
} 
catch (IOException e) { 
    //You'll need to add proper error handling here 
} 

//Find the view by its id 
TextEdit tv = (TextEdit)findViewById(R.id.text_view); 

//Set the text 
tv.setText(text); 

원래 포스트 (How can I read a text file from the SD card in Android?)

솔루션 (코드 (TABLE_NAME에 삽입하여 데이터 삽입해야합니다 아랍 명령을 통해 데이터를 유지하고이 문제에 대한 SQLite는의
0

솔루션 아랍어 텍스트() 값은()) 아랍어는 영어로 아무 문제)에 대한 직접이 SQLite는 데이터를 삽입하지 마십시오

public class SQLiteAdapter 
public static final String MYDATABASE_NAME = "TestSQLilte.s3db"; 
@SuppressLint("SdCardPath") 
// Do not forget This code DB_DIR Because the program does not work on Mobile  without this code 
    private static String DB_DIR = "/data/data/PackageName/databases/"; 
    @SuppressWarnings("unused") 
// Do not forget This code DB_DIR Because the program does not work on Mobile without this code 

    private static String DB_PATH = DB_DIR + MYDATABASE_NAME; 
    public static final String MYDATABASE_TABLE = "Table_Name"; 
    public static final int MYDATABASE_VERSION = 2; 
    public static final String KEY_ID = "_id"; 
    public static final String KEY_Name = "Name"; 
    public static final String KEY_Adress = "Address"; 
    public static final String KEY_Area = "Phone"; 

    private static final String SCRIPT_CREATE_DATABASE = 
      "create table IF NOT EXISTS " + MYDATABASE_TABLE + " (" 
      + KEY_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " 
      + KEY_Name + " Text not null" 
       + ", " 
      + KEY_Adress + " Text not null" 
       + ", " 
      + KEY_Phone + " Text not null);"; 
    private Context context; 
    public SQLiteAdapter(Context c){ 
    context = c; 
} 

// 프로그램이 코드없이 모바일에서 작동하지 않기 때문에이 코드 DB_DIR 잊지 마세요 16,공공 SQLiteAdapter openToRead()()이 코드 공공 SQLiteAdapter openToWrite없이 프로그램이 모바일에서 작동하지 않기 때문에이 코드 DB_DIR 잊지 마세요 android.database.SQLException {

 sqLiteHelper = new SQLiteHelper(context, MYDATABASE_NAME, null, MYDATABASE_VERSION); 

     DB_PATH = context.getDatabasePath(MYDATABASE_NAME).getAbsolutePath(); 

     sqLiteDatabase = sqLiteHelper.getReadableDatabase(); 

     return this; 
    } 

//을 던졌습니다 android.database가 발생합니다. SQLException { sqLiteHelper = 새 SQLiteHelper (컨텍스트, MYDATABASE_NAME, null, MYDATABASE_VERSION);

  DB_PATH = context.getDatabasePath(MYDATABASE_NAME).getAbsolutePath(); 
      sqLiteDatabase = sqLiteHelper.getWritableDatabase(); 
      return this; 
     } 
// Do not forget This code mySQLiteAdapter.insert Because the program does not Display arabic without this code 
    public long insert(String Name,String Adress,String Phone){ 
     ContentValues contentValues = new ContentValues(); 
     contentValues.put(KEY_About_Content, Name); 
     contentValues.put(KEY_Adress,Adress); 
     contentValues.put(KEY_Area ,Area); 
     return sqLiteDatabase.insert(MYDATABASE_TABLE, null, contentValues); 
     } 
    public class MainActivity 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.Test); 
    mySQLiteAdapter = new SQLiteAdapter(this); 
     mySQLiteAdapter.openToWrite(); 
    // Do not forget This code mySQLiteAdapter.insert Because the program does not Display arabic without this code 
    mySQLiteAdapter.insert ("1الاسم","العنوان","التلفون"); 
    mySQLiteAdapter.insert ("2الاسم","العنوان","التلفون"); 
    mySQLiteAdapter.insert ("3الاسم","العنوان","التلفون"); 
    mySQLiteAdapter.insert ("4الاسم","العنوان","التلفون"); 
} 

I've been suffering from this problem, thank God, it has been resolved in this wa 
관련 문제