有`ListView.invalidateViews()'和'Adapter.notifyDataSetChanged()“有什么区别?有什么区别、invalidateViews、Li

2023-09-12 07:41:06 作者:你都不值得我洗头

有间 ListView.invalidateViews任何区别() Adapter.notifyDataSetChanged()

推荐答案

嗯,是的,有。

ListView.invalidateViews()是用来告诉ListView中其所有子项的意见(重绘他们)无效。 注意,这里并不需要同等数量的意见比项目。的这是因为一个ListView循环利用项目的意见和移动周围的屏幕一个聪明的办法,而你滚动。

ListView.invalidateViews() is used to tell the ListView to invalidate all its child item views (redraw them). Note that there not need to be an equal number of views than items. That's because a ListView recycles its item views and moves them around the screen in a smart way while you scroll.

Adapter.notifyDataSetChanged(),另一方面,是要告诉大家,什么是适合的内容已更改适配器的观察者。通报改变了数据集将导致列表视图再次调用你的适配器的方法来调整滚动条,重新生成项目的意见,等等...

Adapter.notifyDataSetChanged() on the other hand, is to tell the observer of the adapter that the contents of what is being adapted have changed. Notifying the dataset changed will cause the listview to invoke your adapters methods again to adjust scrollbars, regenerate item views, etc...

在大多数情况下,你可能需要使用 notifyDataSetChanged ,而不是 invalidateViews 的,但它肯定取决于你试图完成。

Most of the time you would want to use notifyDataSetChanged instead of invalidateViews, but it certainly depends on what you are trying to accomplish.