根据返回的参数来判断 多条目

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;
        }
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值