我有三列,第一個id,第二個標題和第三個主體。如何獲得SQLite數據庫列值在android中爲列表
像這樣
id title body
1 t1 b1
2 t2 b2
3 t3 b3
所以,我想在列表標題和顯示與ListView和如果我點擊標題T2然後顯示相應的可點擊的標題的身體。
我做了什麼。
DatabaseHelper.java
public Cursor retriveTitle(String [] title) {
Cursor c = null;
c = myDataBase.rawQuery(
"select id,title from book,", title);
return c;
}
Main.java
private void displayTitle() {
try {
myDataBase = (new DatabaseHelper(this)).getWritableDatabase();
} catch (IOException e) {
e.printStackTrace();
}
Cursor cursor = myDataBase.rawQuery("SELECT b.id, b.title FROM book b ", new String[] { "" });
String test=cursor.getString(cursor
.getColumnIndex("title"));
//How to display title of book in listview
}
得到這個:
01-18 14:20:03.401: E/AndroidRuntime(6704): Caused by: java.lang.IllegalArgumentException: Cannot bind argument at index 1 because the index is out of range. The statement has 0 parameters.
我已經使用的數據庫文件,根據此博客帖子:Using your own SQLite database in Android applications