package com.bjzc.bhzhgd.adapter;

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

import com.bjzc.bhzhgd.DBModel.WjbrwinfoList;
import com.bjzc.bhzhgd.R;
import com.zhy.autolayout.utils.AutoUtils;

import java.util.List;

/**
 * Created by ruihong on 2018/7/23.
 */

public class WjbxjAdapter extends BaseAdapter {

    private Context context;
    private List<WjbrwinfoList> list;
    private CallBack mCallBack;

    public WjbxjAdapter(Context context, List<WjbrwinfoList> list, CallBack mCallBack) {
        this.context = context;
        this.list = list;
        this.mCallBack = mCallBack;
    }

    public interface CallBack {
        void Click(View view);
    }

    @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 View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder;
        if (view == null) {
            holder = new ViewHolder();
            view = LayoutInflater.from(context).inflate(R.layout.wjbxz_item, viewGroup, false);
            holder.cb = view.findViewById(R.id.cb);
            holder.tv_wjb = view.findViewById(R.id.tv_wjb);

            view.setTag(holder);
            AutoUtils.autoSize(view);
        } else {
            holder = (ViewHolder) view.getTag();
        }

        holder.cb.setChecked(list.get(i).isChecked());
        holder.tv_wjb.setText(list.get(i).getFILEBAGTITLE() + list.get(i).getJHTITLE() + "---文件包号:" + list.get(i).getFILEBAGID());

        holder.cb.setTag(i);
        holder.cb.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mCallBack.Click(view);
            }
        });
        return view;

    }


    static class ViewHolder {
        CheckBox cb;
        TextView tv_wjb;

    }
}
