【问题标题】:Read all rows at once一次读取所有行
【发布时间】:2011-09-18 16:36:27
【问题描述】:

我正在尝试读取 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));
} 

关于如何实现这一点的任何建议?

【问题讨论】:

  • 您是否阅读过关于ListView 和适配器的任何 教程? Here's one。您可能还想查看BaseAdapter。如果要显示自定义数据,请编写一个扩展它的类。

标签: android sqlite listview android-sqlite


【解决方案1】:

您必须使用自定义 CursorAdapter。查看本教程:

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

【讨论】:

    猜你喜欢
    • 2011-09-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-01
    相关资源
    最近更新 更多