public abstract class MyBaseAdapter<T> extends BaseAdapter {
protected List<T> list;
protected LayoutInflater mLayoutInflate;this
public MyBaseAdapter(Context context, List<T> list) {
mLayoutInflate = LayoutInflater.from(context);
this.list = list;
}指針
public int getCount() {
//防止集合爲null時,報空指針錯誤
//當集合爲null時,返回0
return list!=null? list.size():0;
}繼承
public Object getItem(int position) {
return list.get(position);
}get
public long getItemId(int position) {
return position;
}
}it
外部調用的時候必需要重寫getView方法;io
數據源使用泛型,不定死數據源,繼承的子類能夠直接調用數據源。class