对ListView和GridView适配器的在封装,直接继承此类即可
/**
* Created by wkk on 2016/2/26.
*/
import java.util.ArrayList;
import java.util.Collection;
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 {
private List<T> list;
protected LayoutInflater inflater;
public void add(T t) {
list.add(t);
}
public void addList(Collection<? extends T> t) {
list.addAll(t);
}
public void remove(T t) {
list.remove(t);
}
public void removeList(Collection<? extends T> t) {
list.removeAll(t);
}
public List<T> getList() {
return list;
}
public MyBaseAdapter(Context context) {
super();
list = new ArrayList<T>();
inflater = LayoutInflater.from(context);
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return list.size();
}
@Override
public T getItem(int position) {
// TODO Auto-generated method stub
return list.get(position);
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public abstract View getView(int position, View convertView,
ViewGroup parent);
}