import java.util.LinkedList;
import java.util.List; import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter; public abstract class MyBaseAdapter<T> extends BaseAdapter {
protected Context mContext;
protected LayoutInflater mInflater;
protected List<T> mDatas = new LinkedList<T>(); public MyBaseAdapter(Context context, List<T> datas) {
mContext = context;
mInflater = LayoutInflater.from(context);
if (datas != null) {
mDatas = datas;
}
} public void addItemLast(List<T> datas) {
mDatas.addAll(datas);
} public void addItemTop(List<T> datas) {
mDatas = datas;
} @Override
public int getItemViewType(int position) {
return super.getItemViewType(position);
} @Override
public int getViewTypeCount() {
return super.getViewTypeCount();
} public MyBaseAdapter(Context context, List<T> datas,int round) {
mContext = context;
mInflater = LayoutInflater.from(context);
if (datas != null) {
mDatas = datas;
}
} @Override
public int getCount() {
int count=0;
if(mDatas.size()>0){
count=mDatas.size();
}
return count;
} @Override
public Object getItem(int position) {
return mDatas.get(position);
} @Override
public long getItemId(int position) {
return position;
} /**
* 移除一条数据集合
* @param position
*/
public void remove(int position){
mDatas.remove(position);
} /**
* 移除所有数据
*/
public void removeAll(){
mDatas.clear();
} public List<T> getDatas() {
return mDatas;
} @Override
public View getView(int position, View convertView, ViewGroup parent) {
return createView(position,convertView,parent);
} /***
*
* @param position
* @param convertView
* @param parent
* @return
*/
public abstract View createView(int position, View convertView, ViewGroup parent) ; }
05-11 13:55