项目中自己一直用到的baseAdapter的类

  1 import java.util.LinkedList;
  2 import java.util.List;
  3 
  4 import android.content.Context;
  5 import android.view.LayoutInflater;
  6 import android.view.View;
  7 import android.view.ViewGroup;
  8 import android.widget.BaseAdapter;
  9  
 10 
 11 
 12 public abstract class MyBaseAdapter<T> extends BaseAdapter {
 13     protected Context mContext;
 14     protected LayoutInflater mInflater;
 15     protected List<T> mDatas = new LinkedList<T>();  
 16 
 17     public MyBaseAdapter(Context context, List<T> datas) {
 18         mContext = context;
 19         mInflater = LayoutInflater.from(context); 
 20         if (datas != null) {
 21             mDatas = datas;
 22         }
 23     }
 24     
 25     public void addItemLast(List<T> datas) {
 26         mDatas.addAll(datas);
 27     }
 28 
 29     public void addItemTop(List<T> datas) {
 30         mDatas = datas;
 31     }
 32     
 33     @Override
 34     public int getItemViewType(int position) { 
 35         return super.getItemViewType(position);
 36     }
 37 
 38     @Override
 39     public int getViewTypeCount() { 
 40         return super.getViewTypeCount();
 41     }
 42     
 43     public MyBaseAdapter(Context context, List<T> datas,int round) {
 44         mContext = context;
 45         mInflater = LayoutInflater.from(context); 
 46         if (datas != null) {
 47             mDatas = datas;
 48         }
 49     }
 50      
 51 
 52     @Override
 53     public int getCount() {
 54         int count=0;
 55         if(mDatas.size()>0){
 56             count=mDatas.size();
 57         }
 58         return count;
 59     }
 60 
 61     @Override
 62     public Object getItem(int position) { 
 63         return mDatas.get(position);
 64     }
 65 
 66     @Override
 67     public long getItemId(int position) {
 68         return position;
 69     }
 70     
 71     /**
 72     * 移除一条数据集合
 73     * @param position
 74     */
 75     public void remove(int position){
 76         mDatas.remove(position);
 77     }
 78      
 79     /**
 80     * 移除所有数据
 81     */
 82     public void removeAll(){
 83         mDatas.clear();
 84     }
 85 
 86     public List<T> getDatas() {
 87         return mDatas;
 88     }
 89 
 90     @Override
 91     public View getView(int position, View convertView, ViewGroup parent) {
 92         return createView(position,convertView,parent);
 93     } 
 94     
 95     
 96     /***
 97      * 
 98      * @param position 
 99      * @param convertView
100      * @param parent
101      * @return
102      */
103     public abstract View  createView(int position, View convertView, ViewGroup parent) ;
104 
105 }
View Code

 

你可能感兴趣的:(项目中自己一直用到的baseAdapter的类)