您好,我是Android Sqlite数据库的新手。我想将我的所有值从Sqlite列解析为Array。它看起来像是在下面:
id name
1 Peter
2 Mary
3 Tom
4 Elsa
Android阵列:
String[] NameArray = new String[4];
Int[] idArray = new Int[4];
答案 0 :(得分:2)
String Table_Name="name of table";
String selectQuery = "SELECT * FROM " + Table_Name;
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
cursor.moveToFirst();
String[] NameArray = new String[cursor.count()];
String[] idArray = new String[cursor.count()];
int i = 0;
while(cursor.moveToNext()){
String uname = cursor.getString(cursor.getColumnIndex("name"));
NameArray [i] = uname;
String id= cursor.getString(cursor.getColumnIndex("id"));
idArray [i] = id;
i++;
}
db.close();