public abstract class MyBaseAdapter extends BaseAdapter {? ?
?public Listdate;? ??
protected Context mContext;? ?
?private LayoutInflater mInflater;? ?
?protected String type;? ?
?public MyBaseAdapter(Context mContext,Listdate,String type) {? ? ? ?
?super();? ? ? ?
?this.mContext = mContext;? ? ? ?
?this.date = date;? ? ? ??
this.type = type;? ? ? ??
mInflater = LayoutInflater.from(mContext);? ? }? ??
@Override? ?
?public int getCount() {? ? ? ?
?return date == null ? 0 : date.size();? ? }? ?
?@Override? ??
public T getItem(int position) {? ? ??
? if (position < date.size()){? ? ? ? ? ? return date.get(position);? ? ? ? }? ? ?
?? return null;??
? }? ??
@Override? ?
?public long getItemId(int position) {? ? ? ? return position;? ? }? ?
?@Override??
?public View getView(int position, View convertView, ViewGroup parent) {? ? ??
? return createView(position, convertView, parent, mInflater);? ? }? ??
public abstract View createView(int position, View convertView, ViewGroup parent, LayoutInflater inflater);??
? /**? ? * 添加更多數據? ? * @param data? ? */? ??
public void addMore(Listdata) {? ? ?
?? this.date.addAll(data);? ? ?
?? this.notifyDataSetChanged();??
? }??
? /**? ? * 更新數據? ? *? ? * @param data? ? */? ?
?public void changeData(Listdata) {
this.date = data;
this.notifyDataSetChanged();
}
/**
* 是否包含目標元素
* @param t
* @return
*/
public boolean hasContent(T t) {
return date.contains(t);
}
/**
* 刪除指定元素
* @param t
* @return
*/
public boolean remove(T t) {
boolean remove = date.remove(t);
if (remove) {
this.notifyDataSetChanged();
}
return remove;
}
/**
* 清空adapter
*/
public void clear() {
if (date == null) {
return;
}
date.clear();
this.notifyDataSetChanged();
}
}