多条目加载

class MyAdapter extends BaseAdapter{
    List<DataDataBean.ResultBean.ListBean> list;
    Context context;
    private int TitleView=0;//只有标题
    private int LeftView=1;//图片在左
    private int RightView=2;//图片在右
    private int BottomView=3;//图片在下
    public MyAdapter(List<DataDataBean.ResultBean.ListBean> list, Context context) {
        this.list=list;
        this.context=context;
    }


    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }
    //数量
    @Override
    public int getViewTypeCount() {
        return 4;
    }
    //类型
    @Override
    public int getItemViewType(int position) {
        if(position%4==0){
            return TitleView;
        }else if(position%4==1){
            return LeftView;
        }else if(position%4==2){
            return RightView;
        }
        return BottomView;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        //判断
        if(getItemViewType(position)==TitleView){
            TitleHolder titleHolder;
            if (convertView==null){
                convertView=View.inflate(context,R.layout.title_layout,null);
                titleHolder=new TitleHolder();
                titleHolder.des= (TextView) convertView.findViewById(des);
                convertView.setTag(titleHolder);
            }else{
                titleHolder= (TitleHolder) convertView.getTag();
            }
            titleHolder.des.setText(list.get(position).getTitle());
        }else if(getItemViewType(position)==LeftView){
            LeftHolder leftHolder;
            if (convertView==null){
                convertView=View.inflate(context,R.layout.left_layout,null);
                leftHolder=new LeftHolder();
                leftHolder.des= (TextView) convertView.findViewById(des);
                leftHolder.img= (ImageView) convertView.findViewById(R.id.img);
                convertView.setTag(leftHolder);
            }else{
                leftHolder= (LeftHolder) convertView.getTag();
            }
            leftHolder.des.setText(list.get(position).getTitle());
            ImageLoader.getInstance().displayImage(list.get(position).getFirstImg(),leftHolder.img,ImageUtil.getDefaultOption());
        }else if(getItemViewType(position)==RightView){
            RightHolder rightHolder;
            if (convertView==null){
                convertView=View.inflate(context,R.layout.right_layout,null);
                rightHolder=new RightHolder();
                rightHolder.des= (TextView) convertView.findViewById(des);
                rightHolder.img= (ImageView) convertView.findViewById(R.id.img);
                convertView.setTag(rightHolder);
            }else{
                rightHolder= (RightHolder) convertView.getTag();
            }
            rightHolder.des.setText(list.get(position).getTitle());
            ImageLoader.getInstance().displayImage(list.get(position).getFirstImg(),rightHolder.img,ImageUtil.getDefaultOption());
        }else if(getItemViewType(position)==BottomView){
            BottomHolder bottomHolder;
            if (convertView==null){
                convertView=View.inflate(context,R.layout.bottom_layout,null);
                bottomHolder=new BottomHolder();
                bottomHolder.des= (TextView) convertView.findViewById(des);
                bottomHolder.img= (ImageView) convertView.findViewById(R.id.img);
                convertView.setTag(bottomHolder);
            }else{
                bottomHolder= (BottomHolder) convertView.getTag();
            }
            bottomHolder.des.setText(list.get(position).getTitle());
            ImageLoader.getInstance().displayImage(list.get(position).getFirstImg(),bottomHolder.img,ImageUtil.getDefaultOption());
        }
        return convertView;
    }
    class TitleHolder{
        TextView des;
    }
    class LeftHolder{
        TextView des;
        ImageView img;
    }
    class RightHolder{
        TextView des;
        ImageView img;
    }
    class BottomHolder{
        TextView des;
        ImageView img;
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值