public abstract class ItemAdapter<T> extends BaseAdapter {
继承BaseAdapter并重载4个方法且定义两个成员变量 protected Context context; protected List<T> list; public ItemAdapter(Context context) { this.context = context; } @Override public int getCount() { return null == list ? 0 : list.size(); } @Override public T getItem(int position) { return list.get(position); } @Override public long getItemId(int position) { return position; } @Override public abstract View getView(int position, View convertView, ViewGroup parent); public List<T> getList() { return list; } public void setList(List<T> list) { this.list = list;
注意要刷新 notifyDataSetChanged();}
其他适配器需要继承此适配器