天天看點

【J】BaseAdapter的使用與優化

簡要介紹BaseAdapter,推薦一篇關于ListView, Adapter, getView的很好的博文

1、什麼是BaseAdapter

資料擴充卡之一,資料的來源與顯示的适配

ListView/GridView的顯示與緩存機制:需要時才顯示,顯示完就被回收到緩存

2、BaseAdapter的基本結構

public int getCount() {return 0;}
public Object getItem(int position) {
    return null;
}
public long getItemId(int position) {return position;}
public View getView(int position, View convertView, ViewGroup parent) {return null;}//可以在這個方法中充分利用ListView的緩存機制(避免過多的建立View,convertView),使用ViewHolder更加進階的進行了優化(避免頻繁的findViewById)
           

非常好的一篇文章推薦:

HowTo: ListView, Adapter, getView and different list items’ layouts in one ListView

繼續閱讀