自定义BaseAdapter
来源:互联网 发布:淘宝店铺信誉怎么提升 编辑:程序博客网 时间:2024/05/02 04:16
自定义一个类继承自BaseAdapter,将一些Adapter中相同的方法封装到自定义类中,在写Adapter的时候直接继承自这个自定义类
public abstract classMyBaseAdapter<T> extends BaseAdapter {
protectedContext context;
protectedLayoutInflater inflater;
protectedArrayList<T> myList=new ArrayList<T>();
publicMyBaseAdapter(Context context){
this.context=context;
this.inflater=LayoutInflater.from(context);
}
//封装加数据的方法--1条 多条
publicvoid appendData(T t,boolean isClearOld){
if(t==null)
return;
if(isClearOld)
myList.clear();
myList.add(t);
}
publicvoid appendData(ArrayList<T> data,boolean isClearOld){
if(data==null)
return;
if(isClearOld)
myList.clear();
myList.addAll(data);
}
//封装加数据的方法--1条 多条 在顶部添加
publicvoid appendDataTop(T t,boolean isClearOld){
if(t==null)
return;
if(isClearOld)
myList.clear();
myList.add(0,t);
}
publicvoid appendDataTop(ArrayList<T> data,boolean isClearOld){
if(data==null)
return;
if(isClearOld)
myList.clear();
myList.addAll(0,data);
}
publicvoid update(){
this.notifyDataSetChanged();
}
publicvoid clear(){
myList.clear();
}
publicint getCount() {
if(myList==null)
return0;
returnmyList.size();
}
publicT getItem(int position) {
if(myList==null)
returnnull;
if(position>myList.size()-1)
returnnull;
returnmyList.get(position);
}
publiclong getItemId(int position) {
returnposition;
}
publicView getView(int position, View convertView, ViewGroup parent) {
returngetMyView(position, convertView, parent);
}
publicabstract View getMyView(int position, View convertView, ViewGroup parent);
}
- 自定义BaseAdapter
- 自定义BaseAdapter
- 自定义BaseAdapter
- 自定义BaseAdapter
- 自定义BaseAdapter
- BaseAdapter数据刷新,自定义BaseAdapter
- android自定义 BaseAdapter
- android AutoCompleteTextView 自定义BaseAdapter
- 自定义Adapter:BaseAdapter
- Android自定义适配器BaseAdapter
- 实现自定义的BaseAdapter
- android AutoCompleteTextView 自定义BaseAdapter
- 自定义BaseAdapter[转]
- BaseAdapter自定义实现代码
- 自定义BaseAdapter[转]
- android AutoCompleteTextView 自定义BaseAdapter
- 自定义PopupWindow+BaseAdapter+Anim
- android 自定义适配器BaseAdapter
- 使用Maven_Jetty构建Struts2工程
- reference demo
- android教学Intent实现activity之间的跳转
- 《人月神话》的观点:是或非?-转贴
- 可选择也可输入的下拉列表框,html文件
- 自定义BaseAdapter
- uboot 源码官方下载地址
- 自然语言处理(nlp)的流程图
- [Golang]妙用channel
- Java处理带BOM(字节顺序标记)的文本
- OpenCV函数cvFindContours
- c#数据库领域模型操作类
- 黑马程序员——Java面向对象之构造方法、静态、this关键字
- OpenCV数据结构之Mat