一次读取所有行

时间:2011-06-20 13:10:51

标签: android sqlite listview android-sqlite

我正在尝试读取SQLite表中的所有行,并在ListView中一次显示所有行。这是我逐行阅读的方式:

//---get all titles---
db.open();
Cursor c = db.getAllTitles();
String text = "";
if (c.moveToFirst()){
    do {          
        DisplayTitle(c, text);
    } while (c.moveToNext());
}
db.close();

public void DisplayTitle(Cursor c, String text){
      ListView.setText("id: " + c.getString(0) + "\n" + "ISBN: " + c.getString(1) 
    + "\n" + "TITLE: " + c.getString(2) + "\n" + "PUBLISHER:  " + c.getString(3));
} 

有关如何实现这一目标的任何建议吗?

1 个答案:

答案 0 :(得分:2)

您必须使用Custom CursorAdapter。看看这个教程:

http://thinkandroid.wordpress.com/2010/01/11/custom-cursoradapters/