问题
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