多条目加载

package com.bwie.week_two.apdater;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bwie.week_two.MainActivity;
import com.bwie.week_two.R;
import com.bwie.week_two.bean.Uibean;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.List;

public class Myapdater  extends BaseAdapter {
    Context context;
    List<Uibean.ResultBean.DataBean> list;

    public Myapdater(Context context, List<Uibean.ResultBean.DataBean> list) {
        this.context = context;
        this.list = list;
    }

    @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 View getView(int position, View convertView, ViewGroup parent) {

        int itemViewType = getItemViewType(position);

        switch (itemViewType){

            case 1:
                ViewHoderone hoderone = null;
                if(convertView==null) {
                    convertView = View.inflate(context, R.layout.item1, null);
                    hoderone = new ViewHoderone();
                    hoderone.title=convertView.findViewById(R.id.titles);
                    hoderone.image=convertView.findViewById(R.id.images_view);

                    convertView.setTag(hoderone);
                }else{

                    hoderone= (ViewHoderone) convertView.getTag();
                }

                hoderone.title.setText(list.get(position).getTitle());
                ImageLoader.getInstance().displayImage(list.get(position).getUrl(),hoderone.image);
                break;

            case 2:


                ViewHodertwo hodertwo = null;
                if(convertView==null) {
                    convertView = View.inflate(context, R.layout.item2, null);
                    hodertwo = new ViewHodertwo();
                    hodertwo.image_01=convertView.findViewById(R.id.image_view1);
                    hodertwo.image_02=convertView.findViewById(R.id.image_view2);
                    hodertwo.image_03=convertView.findViewById(R.id.image_view3);
                    convertView.setTag(hodertwo);
                }else{

                    hodertwo= (ViewHodertwo) convertView.getTag();
                }

                ImageLoader.getInstance().displayImage(list.get(position).getThumbnail_pic_s(),hodertwo.image_01);
                ImageLoader.getInstance().displayImage(list.get(position).getThumbnail_pic_s02(),hodertwo.image_02);
                ImageLoader.getInstance().displayImage(list.get(position).getThumbnail_pic_s03(),hodertwo.image_03);

                break;
        }

        return convertView;
    }


    @Override
    public int getViewTypeCount() {
        return 3;
    }

    @Override
    public int getItemViewType(int position) {
        String images = list.get(position).getThumbnail_pic_s();
        if(images==null&&images!=null){

            return 1;
        }else {
            return 2;
        }

      //  return super.getItemViewType(position);
    }

    class ViewHoderone{
        TextView title;
        ImageView image;

    }
    class  ViewHodertwo{

        ImageView image_01;
        ImageView image_02;
        ImageView image_03;
    }

}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值