【发布时间】:2013-12-17 08:36:23
【问题描述】:
我有三列,第一个 id,第二个标题和第三个正文。
这样
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
【问题讨论】:
标签: android listview android-sqlite