`ListView.invalidateViews()` 和 'Adapter.notifyDataSetChanged()' 之间有什么区别吗? [英] Is there any difference between `ListView.invalidateViews()` and 'Adapter.notifyDataSetChanged()'?

查看:27
本文介绍了`ListView.invalidateViews()` 和 'Adapter.notifyDataSetChanged()' 之间有什么区别吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ListView.invalidateViews()Adapter.notifyDataSetChanged() 有什么区别吗?

Is there any difference between ListView.invalidateViews() and 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.

这篇关于`ListView.invalidateViews()` 和 'Adapter.notifyDataSetChanged()' 之间有什么区别吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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