Android - what is the meaning of StableIDs?

后端 未结 2 745
[愿得一人]
[愿得一人] 2020-11-29 06:06

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

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-29 06:42

    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.

    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.

提交回复
热议问题