我有三列,第一个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