adapter模板

来源:互联网 发布:Sony编程 编辑:程序博客网 时间:2024/06/05 15:10
public abstract class MyBaseAdapter<T> extends BaseAdapter {
Context context;
List<T> datasource;
LayoutInflater inflater;


public MyBaseAdapter(Context context, List<T> datasource) {
super();
this.context = context;
this.datasource = datasource;
this.inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);


}


@Override
public int getCount() {
// TODO Auto-generated method stub
return datasource.size();
}


@Override
public T getItem(int position) {
// TODO Auto-generated method stub
return datasource.get(position);
}


@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}


@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
return getItemView(position, convertView, parent);
}


public abstract View getItemView(int position, View convertView,
ViewGroup parent);


public void addAll(List<T> list, Boolean flag) {
if (flag) {
datasource.clear();

}
datasource.addAll(list);
notifyDataSetChanged();
}


public void remov(T t) {
datasource.remove(t);
notifyDataSetChanged();
}
0 0