改善android listview的性能以进行刷新和滚动 [英] Improve android listview performance for refreshing and scrolling
问题描述
我有一个 ListView
,其中 onItemClick
所选项目会更改其布局,并弹出不同的按钮.如果选择了其他任何项目,则先前选择的项目将恢复正常.我的 ListView
适配器工作正常,但是使用适配器中的 notifyDataSetChanged()
刷新整个列表会花费很多时间.
I have a ListView
which onItemClick
selected item changes its layout, pops different buttons. If any other item is selected, the previous selected one returns to normal. My ListView
adapter works fine but refreshing the whole list with notifyDataSetChanged()
in my adapter takes too much time.
我的问题是仅刷新 ListView
中的更改项.另外,我也想提出更好的滚动性能建议.
My problem is to refresh only the changed items in the ListView
.
And also I would like to have suggestions for better scrolling performance.
推荐答案
尝试实现 View Holder模式,它提高了 ListViews
使ListView滚动平滑|Android开发人员
在Android中使用列表(ListView)-教程-Vogella
来自文档:
在滚动
ListView
时,您的代码可能会频繁调用findViewById()
,这可能会降低性能.即使适配器返回膨胀视图以进行回收,您仍然需要查找元素并进行更新.重复使用findViewById()
的一种方法是使用视图持有人" 设计模式.
Your code might call
findViewById()
frequently during the scrolling ofListView
, which can slow down performance. Even when the Adapter returns an inflated view for recycling, you still need to look up the elements and update them. A way around repeated use offindViewById()
is to use the "view holder" design pattern.
这篇关于改善android listview的性能以进行刷新和滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!