常用适配器
1.ArrayAdapter 三个参数(上下文,布局,数据)
2.SimpleAdapter 五个参数(上下文,数据,布局,键的数组,值的数组)
3.BaseAdapter 要重写4个方法 getCount() getItem() getItemId() getView()
BaseAdapter的高效使用方法
结合ViewHolder类使用
案例

布局
1.主布局是一个ListView
2.选项布局是一张图片一个标题一内容
创建ItemBean类
承载三个参数,图片img,标题title,内容content

创建MyAdapter继承BaseAdapter
1.成员变量
LayoutInflater inflater list<ItemBean> list
2.构造函数
传递两个变量,一个是上下文,一个是list<ItemBean>的泛型集合
this.inflater = LayoutInflater.from(context)
this.list = list
3.创建ViewHolder类
三个成员变量public ImageView img; public TextView title; public TextView content;
4.具体代码

MainActivity具体代码

网友评论