DTM(ada)

package com.example.adapter;

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

import com.example.bean.DataInfo;
import com.example.day8_lianxi2.R;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.List;

/**
 * Created by 杨柳 on 2018/7/13.
 */

public class MyAdapter extends BaseAdapter{
    private List<DataInfo.ResultsBean> list;
    private Context context;

    public MyAdapter(List<DataInfo.ResultsBean> list, Context context) {
        this.list = list;
        this.context = context;
    }

    //添加到集合元素0的前面
    public void  add(List<DataInfo.ResultsBean> resultsBeans){
        this.list.addAll(0,resultsBeans);
        notifyDataSetChanged();
    }

    //在集合后面添加元素
    public void loadMore(List<DataInfo.ResultsBean> resultsBeans){
        this.list.addAll(resultsBeans);
        notifyDataSetChanged();
    }
    @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 int getItemViewType(int position) {
        List<String> images = list.get(position).getImages();
        if (images == null || images.size() == 0){
            return  0 ;
        }else if (images.size()>2){
            return 3;
        }else {
            return  1;
        }
    }

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

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        int itemViewType = getItemViewType(i);
        switch (itemViewType){
            case 0:
                ViewHolde1 holder1 = null;
                if (view == null ){
                    view = View.inflate(context, R.layout.list1_layout, null);
                    holder1 = new ViewHolde1();
                    holder1.text_title = view.findViewById(R.id.title);
                    view.setTag(holder1);
                }else {
                    holder1 = (ViewHolde1) view.getTag();
                }
                holder1.text_title.setText(list.get(i).getCreatedAt());
                break;

            case 1:
                ViewHolder2 holder2 = null;
                if (view == null ){
                    view = View.inflate(context, R.layout.list2_layout, null);
                    holder2 = new ViewHolder2();
                    holder2.text_title = view.findViewById(R.id.title);
                    holder2.img1 = view.findViewById(R.id.img1);
                    view.setTag(holder2);
                }else {
                    holder2 = (ViewHolder2) view.getTag();
                }
                holder2.text_title.setText(list.get(i).getCreatedAt());
                ImageLoader.getInstance().displayImage(list.get(i).getImages().get(0),holder2.img1);
                break;

            case 3:
                ViewHolder3 holder3 = null;
                if (view == null ){
                    view = View.inflate(context, R.layout.list3_layout, null);
                    holder3 = new ViewHolder3();
                    holder3.text_title = view.findViewById(R.id.title);
                    holder3.img1 = view.findViewById(R.id.img1);
                    holder3.img2 = view.findViewById(R.id.img2);
                    holder3.img3 = view.findViewById(R.id.img3);
                    view.setTag(holder3);
                }else {
                    holder3 = (ViewHolder3) view.getTag();
                }
                holder3.text_title.setText(list.get(i).getCreatedAt());
                ImageLoader.getInstance().displayImage(list.get(i).getImages().get(0),holder3.img1);
                ImageLoader.getInstance().displayImage(list.get(i).getImages().get(1),holder3.img2);
                ImageLoader.getInstance().displayImage(list.get(i).getImages().get(2),holder3.img3);
                break;
        }


        return view;
    }

    public  class ViewHolde1{
        TextView text_title;
    }

    public class ViewHolder2 extends  ViewHolde1{
        ImageView img1;
    }

    public  class ViewHolder3 extends  ViewHolder2{
        ImageView img2;
        ImageView img3;
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值