package edu.hebtu.movingcampus.adapter.base; import java.util.LinkedList; import java.util.List; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; public abstract class AdapterBase<T> extends BaseAdapter { protected List<T> mList =null; /** * list == null, not save adater data state, list!=null, save it's state util next shown * @param list */ public AdapterBase(List<T> list ){ super(); if(list==null) mList=new LinkedList<T>(); else this.mList=list; } public List<T> getList() { return mList; } /* * 往后加 */ public void appendToList(List<T> list) { if (list == null) { return; } mList.addAll(list); notifyDataSetChanged(); } /* * 往前加 */ public void appendToTopList(List<T> list) { if (list == null) { return; } mList.addAll(0, list); notifyDataSetChanged(); } public void clear() { mList.clear(); notifyDataSetChanged(); } @Override public int getCount() { return mList==null?0:mList.size(); } @Override public Object getItem(int position) { // TODO Auto-generated method stub if (position > mList.size() - 1) { return null; } return mList.get(position); } @Override public long getItemId(int position) { // TODO Auto-generated method stub return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { // TODO Auto-generated method stub if (position == getCount() - 1) { onReachBottom(); } return getNextView(position, convertView, parent); } protected abstract View getNextView(int position, View convertView, ViewGroup parent); protected abstract void onReachBottom(); }