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();
}
}