public class MyAdapter extends BaseAdapter {
List<Bean.DataBean> list;
Context context;
public MyAdapter(List<Bean.DataBean> list, Context context) {
this.list = list;
this.context = context;
}
@Override
public int getCount() {
return list.size();
}
@Override
public Object getItem(int i) {
return list.get(i);
}
@Override
public long getItemId(int i) {
return i;
}
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
ViewHolder holder;
// 进行优化
if (view == null){
holder = new ViewHolder();
view= View.inflate(context,R.layout.listview__item,null);
holder.image_item= view.findViewById(R.id.image_item);
holder.text_item = view.findViewById(R.id.text_item);
view.setTag(holder);
}else {
holder = (ViewHolder) view.getTag();
}
// 截取图片
String[] split = list.get(i).getImages().split("\\|");
Glide.with(context).load(split[0]).into(holder.image_item);
holder.text_item.setText(list.get(i).getTitle());
return view;
}
// 进行viewHolder优化
public class ViewHolder{
ImageView image_item;
TextView text_item;
}
}
适配器优化 + 截取
最新推荐文章于 2021-03-26 13:00:45 发布