Android - StableID 的含义是什么? [英] Android - what is the meaning of StableIDs?

查看:35
本文介绍了Android - StableID 的含义是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在实现 ExpandableListView 的 ListAdapter,在工作时我发现我需要覆盖函数 boolean hasStableIds().谁能解释一下稳定ID的含义是什么?我什么时候需要这个?

I'm implementing a ListAdapter of ExpandableListView, while working i see that i need to overide the function boolean hasStableIds(). Can anyone explain please what is the meaning of stable ids? when I need this?

推荐答案

稳定的 ID 允许 ListView 优化项目在 notifyDataSetChanged 调用之间保持相同的情况.它引用的 ID 是从 getItemId 返回的 ID.

Stable IDs allow the ListView to optimize for the case when items remain the same between notifyDataSetChanged calls. The IDs it refers to are the ones returned from getItemId.

没有它,ListView 必须重新创建所有 View,因为它无法知道数据更改之间的项目 ID 是否相同(例如,如果 ID 是只是数据中的索引,它必须重新创建所有内容).有了它,它就可以避免重新创建保留其项目 ID 的 View.

Without it, the ListView has to recreate all Views since it can't know if the item IDs are the same between data changes (e.g. if the ID is just the index in the data, it has to recreate everything). With it, it can refrain from recreating Views that kept their item IDs.

这篇关于Android - StableID 的含义是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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