1. 程式人生 > >getView(int position, View convertView, ViewGroup parent)

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)