java 当调用 ArrayAdapter 中的 getView() 时
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10160475/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
When getView() in ArrayAdapter is called
提问by Adham
When creating a customized adapter
for ListView
in android, I see that I have to create a class the extends ArrayAdapter
class and implements the getView(..)
method.
当创建一个定制adapter
的ListView
android系统中,我看到,我要创建一个类的扩展ArrayAdapter
类并实现getView(..)
方法。
All of that is OK, but I want to know the sequence of calling methods and executing. i.e. in which point of code the getView()
is being called ?
所有这些都可以,但我想知道调用方法和执行的顺序。即在哪个代码点getView()
被调用?
采纳答案by Anamoy
From android docs - An Adapter object acts as a bridge between an AdapterView (such as ListView in your case) and the underlying data for that view. The Adapter provides access to the data items and is also responsible for making a View for each item in the data set.
来自 android docs - Adapter 对象充当 AdapterView(例如您的案例中的 ListView)和该视图的基础数据之间的桥梁。Adapter 提供对数据项的访问,还负责为数据集中的每个项创建一个视图。
So, whenever the ListView needs to display a particular row of data, it requests the associated adapter to provide the view corresponding to that the data at that position through getView() method. This may occur whenever the view needs to be updated on screen (eg. during creation/scroll etc.).
因此,每当 ListView 需要显示特定行的数据时,它都会通过 getView() 方法请求关联的适配器提供与该位置的数据对应的视图。每当需要在屏幕上更新视图时(例如,在创建/滚动期间等),就会发生这种情况。
As an app developer, you need not worry about exactly at which point getView() is being called as long as you provide a concrete getView() implementation in your adapter. Make sure the method is efficient (thumbnails etc should be loaded in a background thread) for optimum performance.
作为应用程序开发人员,只要您在适配器中提供具体的 getView() 实现,您就不必担心确切地调用 getView() 的时间点。确保该方法有效(缩略图等应加载到后台线程中)以获得最佳性能。
回答by Kri
getView() of ArrayAdapter is called multiple times....
ArrayAdapter 的 getView() 被多次调用......
- as an when the new row is added...
- you scroll up and scroll down the list view....
- when the list is notfiedchanged..
- 当添加新行时...
- 您向上滚动并向下滚动列表视图....
- 当列表未更改时..
Refer this link Android custom ArrayAdapter getView method called multiple times - resetting dynamic TextView value
回答by Its not blank
getView(int position, View view, ViewGroup parent)
is called for the
被称为
List of Objects
of the nos of elements using
使用的元素数
getItem(int position)
for the length of our List
对于我们列表的长度
so, it is called nos of times untill your entire list has been allocated a layout and data from list.
因此,在您的整个列表已从列表中分配布局和数据之前,它被称为多次。