package com.example.dell.yuekaomoni20180303.adapter; import android.content.Context; import android.graphics.Bitmap; import android.view.PointerIcon; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.ImageView; import android.widget.TextView; import com.example.dell.yuekaomoni20180303.Bean.bean; import com.example.dell.yuekaomoni20180303.R; import com.nostra13.universalimageloader.core.DisplayImageOptions; import com.nostra13.universalimageloader.core.ImageLoader; import com.nostra13.universalimageloader.core.assist.ImageScaleType; import java.util.List; /** * Created by dell on 2018/3/4. */ public class MyAdapter extends BaseAdapter { private DisplayImageOptions options; private final int a=0; private final int b=1; private final int c=2; private TextView tv1; private ImageView iv1; private ImageView iv2; private ImageView iv3; private ImageView iv4; private ImageView iv5; private ImageView iv6; private List<bean.ResultBean.DataBean> data; private Context context; public MyAdapter(Context context,List<bean.ResultBean.DataBean> data) { this.context = context; this.data = data; options = new DisplayImageOptions.Builder() .cacheInMemory(true)//使用内存缓存 .cacheOnDisk(true)//使用磁盘缓存 .bitmapConfig(Bitmap.Config.RGB_565)//设置图片色彩模式 .imageScaleType(ImageScaleType.EXACTLY)//设置图片的缩放模式 // .displayer(new RoundedBitmapDisplayer(50))//设置圆角 .build(); } @Override public int getCount() { return data.size(); } @Override public Object getItem(int i) { return data.get(i); } @Override public long getItemId(int i) { return i; } @Override public int getItemViewType(int position) { String s1 = data.get(position).getThumbnail_pic_s(); String s2 = data.get(position).getThumbnail_pic_s02(); String s3 = data.get(position).getThumbnail_pic_s03(); if (s1 != null && s2 == null && s3 == null) { return a; } else if (s1 == null && s2 != null && s3 != null) { return b; } else if (s1 != null && s2 != null && s3 != null) { return c; } else { return a; } } @Override public int getViewTypeCount() { return 3; } @Override public View getView(int i, View view, ViewGroup viewGroup) { int type = getItemViewType(i); if(type==a){ if(view==null){ view=View.inflate(context, R.layout.l1,null); iv1 = view.findViewById(R.id.iv1); tv1 = view.findViewById(R.id.tv1); } tv1.setText(data.get(i).getCategory()); ImageLoader.getInstance().displayImage(data.get(i).getThumbnail_pic_s(),iv1,options); return view; }else if(type==b){ if(view==null){ view=View.inflate(context,R.layout.l2,null); iv2 = view.findViewById(R.id.iv2); iv3 = view.findViewById(R.id.iv3); } ImageLoader.getInstance().displayImage(data.get(i).getThumbnail_pic_s(),iv2,options); ImageLoader.getInstance().displayImage(data.get(i).getThumbnail_pic_s02(),iv3,options); return view; }else if(type==c){ if(view==null){ view=View.inflate(context,R.layout.l3,null); iv4 = view.findViewById(R.id.iv4); iv5 = view.findViewById(R.id.iv5); iv6 = view.findViewById(R.id.iv6); } ImageLoader.getInstance().displayImage(data.get(i).getThumbnail_pic_s(),iv4,options); ImageLoader.getInstance().displayImage(data.get(i).getThumbnail_pic_s02(),iv5,options); ImageLoader.getInstance().displayImage(data.get(i).getThumbnail_pic_s03(),iv6,options); return view; }else { return null; } } }
根据返回的参数来判断 多条目
最新推荐文章于 2020-11-30 02:28:16 发布