greendao listview all data from Entity

对着背影说爱祢 提交于 2019-12-21 20:48:28

问题


GreenDAO. Which there is a simple way to display all the records from a Entity in the ListView, and is supported with the auto-update the list. Perhaps Lazylist class? how to use it?


回答1:


Have a look here. I'm using an adapter like this (including a ViewHolder-Pattern to reuse the Views inside the ListView) as well and it is fast even for a lot of records. But this won't be usable if you need auto-update-functionality.

Here are some information about LasyList to explain why:

  • Get LazyList using Query.listLazy(): This will not show new inserted records (or stop deleted records from displaying) automatically, since the records are cached in memory. Thus updates won't be visible, because records are not queried twice.

  • Get LazyList using Query.listLazyUncached(): Updates of already existing records may be visible, but only if the records updated are currently not displayed. Also you should be careful because I think inserting or deleting records may break this list.

To get inserts and deletes into the list you will have to refresh the underlying LazyList and call notifyDataSetChanged().

I'm using this in my Adapter:

public void setLazyList(LazyList<T> list) {
    if (list != lazyList) {
        lazyList.close();
        lazyList = list;
        this.dataValid = lazyList != null;
        notifyDataSetChanged();
    }
}

By the way: If you are using LazyList:

Don't forget to close LazyLists if you are not using them any more!



来源:https://stackoverflow.com/questions/18953168/greendao-listview-all-data-from-entity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!