ListView 的内容在滚动时乱序
所以我对组成 ListView 的不同部分遇到了问题。我将它们放入 ArrayList 中,并使用自定义 ArrayAdapter 连接到 ListView,我之前已经这样做过,所以我不认为那里有问题。最初,列表似乎按正确的顺序排列各个部分,但随后我将向下滚动列表,内容将以错误的顺序加载。然后我向后滚动,一切都变得混乱了。以前有人遇到过这个吗?
谢谢 -杰克
So I am having a problem with the different pieces of that make up my ListView. I put them into an ArrayList and use a custom ArrayAdapter to hook up to the ListView, which I have done before so I don't believe there is a problem there. Initially the list seems to have the pieces in the correct order, but then I will scroll down the list and the contents will then load in incorrect order. I then scroll back up and everything is jumbled. Has anyone run into this before?
Thanks
-Jake
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,您的问题与 List 重用每行的视图这一事实有关。假设您的列表可以看到 5 个项目,但您的 ListAdapter 有 15 个项目。 Android 将创建 5 + 1 个行视图实例,而不是 15 个。列表中的每一行创建一个实例 + 1 个实例用于可以看到顶部和底部的一半。当一行移出可见区域时,列表将回收另一行的视图实例,而不是创建新的一行。如果您每次没有正确重置所有用户界面组件,您就会从显示的其他行中获得工件。您必须确保每次将数组列表中的对象中的数据绑定到每次设置每个字段的视图。
有关详细说明,请参阅
http://www.youtube.com/watch?v=N6YdwzAvwOA&feature =相关
Yes your problem is related to the fact that List reuses the views for each row. So say your list can see 5 items, but your ListAdapter has 15 things in it. Android will create 5 + 1 instances of your row view instead of 15. One for each row in the list + 1 for when half of the top and bottom can be seen. When a row is moved out of the visible area the List will recycle that view instance for another row instead of creating a new one. If you don't properly reset all of the user interface components every time you'll get artifacts from other rows showing up. You must make sure that every time you bind your data from the objects in your array list to the view you set every field every time.
For a better description of this see
http://www.youtube.com/watch?v=N6YdwzAvwOA&feature=related