getView(int position, View convertView, ViewGroup parent)

向上滑动 ListView ,item1 视图被滑出屏幕, item1视图被 回收到 Recycler( View 缓冲池) 中,如要显示 item8视图,先从缓存池中取出item1视图,更新 item8 需要显示的数据,变成了item8视图,把它放到ViewGroup中,ListView要的时候取出来。

ListView 的缓冲机制:需要时才显示,显示完就被会收到缓存。

在这里插入图片描述

public View getView(int position, View convertView, ViewGroup parent)

position:
The position of the item within the adapter’s data set of the item whose view we want.
显示屏中,要出现的一行搜索结果(一个item.xml形成的视图),其在搜索结果中的位置

convertView:
The old view(item的,每一行的视图) to reuse, if possible. Note: You should check that this view is non-null and of an appropriate type before using. If it is not possible to convert this view to display the correct data, this method can create a new view.
随着滑动,屏幕中消失的一行被回收到了缓存, 将其(convertVeiw)取出,在其视图中,更改控件信息(把将要显示的那一行的控件信息填进去),形成了新的即将在ListView中出现的item视图。
如果缓存中没有,要新建视图 convertView = myInflater.inflate(R.layout.item, null);//布局实例化

parent:
The parent that this view will eventually be attached to return A View corresponding to the data at the specified position.
每个item的视图,被放在了parent中,listeview要显示新出现的一行的视图时,把其取出来(把item1视图更改为item8视图后,也把它放到parent)

猜你喜欢

转载自blog.csdn.net/puspos/article/details/83927921
今日推荐