greendao的ListView从实体的所有数据 [英] greendao listview all data from Entity

查看:1263
本文介绍了greendao的ListView从实体的所有数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

GreenDAO。 其中有一个简单的方法从一个实体中的所有记录显示在ListView,并支持自动更新列表。 也许Lazylist类?如何使用它?

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?

推荐答案

深入了解的此处。我使用这样的适配器(包括ViewHolder-模式重用的ListView里面的意见),以及和它的速度很快,即使是很多纪录。但是如果你需要自动更新功能性,这将无法使用。

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.

下面是关于LasyList一些信息来解释为什么:

Here are some information about LasyList to explain why:

  • 获取LazyList使用 Query.listLazy(): 这样就不会显示新插入的记录(或显示停止删除的记录)自动,因为记录被缓存在内存中。 因此,更新将不可见的,因为记录不会被查询两次。

  • 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.

获取LazyList使用 Query.listLazyUncached(): 已经存在的记录的更新可以是可见的,但只有当当前没有显示被更新的记录。 也因为我觉得插入和删除记录可能会打破这个列表中,您应该谨慎。

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.

要获得插入和删除到列表中,你将不得不更新底层LazyList并调用 notifyDataSetChanged()

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();
    }
}

顺便说一句:如果你使用的是LazyList:

By the way: If you are using LazyList:

不要忘了,如果你不使用它们了,收LazyLists!

这篇关于greendao的ListView从实体的所有数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆