Created
August 23, 2012 11:25
-
-
Save holmeszyx/3435739 to your computer and use it in GitHub Desktop.
VariableAdatper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.xxx.view.adpter; | |
| import java.util.List; | |
| import android.content.Context; | |
| import android.view.LayoutInflater; | |
| import android.widget.BaseAdapter; | |
| /** | |
| * 可变内容的Adapter<br> | |
| * 子类可以直接使用 数据集{@link #data}, Context {@link #mContext}, View解析器{@link #infl} | |
| * @author holmes | |
| * | |
| * @param <T> | |
| */ | |
| public abstract class VariableAdatper <T> extends BaseAdapter implements Variable<T>{ | |
| protected List<T> data; | |
| protected Context mContext; | |
| protected LayoutInflater infl; | |
| public VariableAdatper(Context context, List<T> data){ | |
| this.mContext = context; | |
| this.data = data; | |
| infl = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); | |
| } | |
| @Override | |
| public int getCount() { | |
| // TODO Auto-generated method stub | |
| return data.size(); | |
| } | |
| @Override | |
| public Object getItem(int position) { | |
| // TODO Auto-generated method stub | |
| return data.get(position); | |
| } | |
| @Override | |
| public void refresh(List<T> data) { | |
| // TODO Auto-generated method stub | |
| this.data.clear(); | |
| this.data = data; | |
| notifyDataSetChanged(); | |
| } | |
| @Override | |
| public void append(T data) { | |
| // TODO Auto-generated method stub | |
| this.data.add(data); | |
| notifyDataSetChanged(); | |
| } | |
| @Override | |
| public void append(List<T> data) { | |
| // TODO Auto-generated method stub | |
| this.data.addAll(data); | |
| notifyDataSetChanged(); | |
| } | |
| @Override | |
| public T remove(T item) { | |
| // TODO Auto-generated method stub | |
| this.data.remove(item); | |
| notifyDataSetChanged(); | |
| return item; | |
| } | |
| @Override | |
| public T remove(int position) { | |
| // TODO Auto-generated method stub | |
| T item = this.data.get(position); | |
| this.data.remove(position); | |
| notifyDataSetChanged(); | |
| return item; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment