简体   繁体   English

Android在ListView中的每个元素上调用getView

[英]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.

相关问题 Android:ListView在getView()中添加标签? - Android: ListView add label in getView()? Android ListView getView 随机显示图片 - Android ListView getView display image randomly Android,ListView和ArrayAdaptater,getView只调用一次 - Android, ListView and ArrayAdaptater, getView called only once 您正在滑动(onFling)for android的元素的getView吗? - getView of element that you're swiping (onFling) for android? 在Fragment中使用ListView时,适配器不调用getView() - The adapter does not call getView () when using ListView in Fragment android setAdapter不触发getView或不构建ListView - android setAdapter doesn't trigger getView or doesn't build ListView ListView Android中的getView停止工作,仅显示第一个数据 - getView in ListView Android stopped working and shows only first data 未为Android ListView调用适配器的类getView()函数 - Adapter's class getView() function not called for Android ListView Android:从viewPager中的Fragment调用ListView的适配器的getview() - Android: calling getview() for ListView's Adapter from Fragment in viewPager Android ListView:更改数据集并在getView中调用notifyDataSetChanged - Android ListView : changing dataset and calling notifyDataSetChanged inside of getView
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM