package com.bonait.bnframework.modules.home.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.bonait.bnframework.R;
import com.bonait.bnframework.common.db.mode.BPA_MATERIAL;
import com.bonait.bnframework.common.db.res.lcMode;
import com.bonait.bnframework.common.helper.I.MyClickListener;

import java.util.List;


/**
 * 物料数据表格
 */
public class lcsz_adapter extends ArrayAdapter<lcMode> {
    /**
     * 内部点击事件
     */
    private MyClickListener mListener;
    private List<lcMode> datas;
    int resource1;
    public lcsz_adapter(@NonNull Context context, int resource, @NonNull List<lcMode> objects, MyClickListener listener) {
        super(context, resource, objects);
        mListener = listener;
        datas=objects;
        this.resource1=resource;
    }
    //每个子项被滚动到屏幕内的时候会被调用
    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        lcMode lc = (lcMode) getItem(position);//得到当前项选中item实例
        //为每一个子项加载设定的布局
        View view = LayoutInflater.from(getContext()).inflate(resource1, parent, false);
        //分别获取 image view 和 textview 的实例

        TextView xh = view.findViewById(R.id.xh);
        TextView name = view.findViewById(R.id.name);
        TextView bjz = view.findViewById(R.id.bjz);
        TextView zlz = view.findViewById(R.id.zlz);
        // 设置要显示的图片和文字
        xh.setText(lc.num+"");
        name.setText(lc.materialName);
        bjz.setText(lc.warningValue+"");
        zlz.setText(lc.siloszl+"");
        name.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(mListener!=null) mListener.clickListenerNew(view,0,lc);
            }
        });
        bjz.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(mListener!=null) mListener.clickListenerNew(view,0,lc);
            }
        });
        zlz.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(mListener!=null) mListener.clickListenerNew(view,0,lc);
            }
        });
        return view;
    }
}