package com.rehome.sgbaxj.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.rehome.sgbaxj.R;
import com.rehome.sgbaxj.bean.MjList;
import com.zhy.autolayout.utils.AutoUtils;
import java.util.List;

/**
 * Create By HuangWenFei
 * 创建日期：2023-07-25 14:16
 * 描述：保安免检计划适配器
 */

public class BamjAdapter extends BaseAdapter {

    private Context context;
    private List<MjList.DataBean> mjjh;
    private CallBack mCallBack;

    public BamjAdapter(Context context, List<MjList.DataBean> mjjh, CallBack mCallBack) {
        this.context = context;
        this.mCallBack = mCallBack;
        this.mjjh=mjjh;
    }

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

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

    @Override
    public Object getItem(int i) {
        return mjjh.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.scxscb_item, viewGroup, false);
            holder.xj_cb = view.findViewById(R.id.xj_cb);
            holder.tv_gwmc = view.findViewById(R.id.tv_gwmc);
            holder.tv_yjzj = view.findViewById(R.id.tv_yjzj);

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


        holder.xj_cb.setChecked(mjjh.get(i).isChecked());
        holder.tv_gwmc.setText(mjjh.get(i).getKhmc());
        holder.tv_yjzj.setText(mjjh.get(i).getZds());



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

    static class ViewHolder {
        CheckBox xj_cb;
        TextView tv_gwmc;
        TextView tv_yjzj;

    }
}