[英]Android call getView on every element in ListView
I understand for efficiency, android only calls the getView method on certain elements in a ListView (those visible, or clicked on, etc.) 我理解效率,android只调用ListView中的某些元素的getView方法(那些可见,或点击等)
http://developer.android.com/reference/android/widget/ArrayAdapter.html#getView http://developer.android.com/reference/android/widget/ArrayAdapter.html#getView
For my custom ArrayAdapter implementation, however, it is important that getView be called for every element in the list (regardless of whether or not it is visible). 但是,对于我的自定义ArrayAdapter实现,重要的是为列表中的每个元素调用getView(无论它是否可见)。
Is this possible to do? 这可能吗?
What do you want to achieve? 你想达到什么目的? GetView is called with every item, is up to you to implement a ViewHolder or something like that in order to re-use the view or not. GetView与每个项目一起调用,取决于您是否要实现ViewHolder或类似的东西,以重新使用视图。 However, you should do. 但是,你应该这样做。
I have some Bitmaps inside of the objects within my listview, which are loaded in getView, however I need them elsewhere on the screen too. 我的列表视图中的对象内部有一些位图,这些位图已加载到getView中,但是在屏幕上的其他地方也需要它们。 The observed behaviour is they load on the screen (elsewhere) only when I scroll to them in the listview. 观察到的行为是,只有当我在列表视图中滚动它们时,它们才会加载到屏幕上(其他地方)。
Simple solution would be to load your images elsewhere and as soon as you load them you can update your list adapter by calling notifyDataSetChanged()
. 一个简单的解决方案是将图像加载到其他位置,并且一旦加载图像,就可以通过调用notifyDataSetChanged()
来更新列表适配器。
Note : You cannot invoke getView() for those list items which are not visible. 注意:您不能为那些不可见的列表项调用getView()。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.