【问题标题】:Ormlite, listViews and adapters?Ormlite、listViews 和适配器?
【发布时间】:2012-09-11 11:49:07
【问题描述】:

我在我的应用程序中运行了 OrmLite,并带有数据库助手等。我查看了 OrmLite 的示例和一些教程。这是我使用 listViews 的代码:

数据库管理员:

public List<Artist> getAllArtists() {
    List<Artist> artists = null;
    try {
        artists = getHelper().getArtistDao().queryForAll();
    } catch (SQLException e) {
            e.printStackTrace();
    }
    return artists;
}

活动:

List<Artist> artists = dataBase.getAllArtists(); 

for (Artist artist : artists) {
     items.add(artist);
}

mAdapter = new ArtistsListCustomAdapter(getActivity(), items);
listView.setAdapter(mAdapter);

这是一个好的方法还是使用我的方法会有麻烦?

从我读到的其他来源,应该使用CursorAdapter 用于listViews 而不是BaseAdapter(我现在在ArtistsListCustomAdapter() 中扩展它)。对我来说,第二次迭代结果来创建数组似乎很尴尬。

我已经找到了一些关于使用适配器的线索,但由于我对 Android 总体来说还比较陌生,所以我真的很感激更多关于“连接点”的线索。就我而言,getAllArtists() 是否应该返回Cursor?这么简单的任务似乎很复杂:

Android Cursor with ORMLite to use in CursorAdapter

【问题讨论】:

    标签: android android-listview ormlite


    【解决方案1】:

    看看这个:

    https://github.com/campnic/ormlite-android-extras

    他们实现了 ormlite 光标适配器。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-08-06
      • 1970-01-01
      • 2010-12-18
      • 2016-03-04
      • 1970-01-01
      • 2012-07-06
      • 1970-01-01
      相关资源
      最近更新 更多