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

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

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

import com.bonait.bnframework.R;
import com.bonait.bnframework.common.constant.DataBus;
import com.bonait.bnframework.common.db.mode.BPA_GOODSRECIPE;
import com.bonait.bnframework.common.helper.I.MyClickListener;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;

public class gongxubuzhou_adapter1 extends ArrayAdapter<BPA_GOODSRECIPE> {
    /**
     * 内部点击事件
     */
    private ArrayList<BPA_GOODSRECIPE> datas= new ArrayList<>();

    private int selectedPosition = -1;// 选中的位置
    int resource1;
    public gongxubuzhou_adapter1(@NonNull Context context, int resource, @NonNull ArrayList<BPA_GOODSRECIPE> objects) {
        super(context, resource, objects);
        datas=objects;
        this.resource1=resource;
    }

    public int getSelectedPosition()
    {
        return selectedPosition;
    }

    public void setSelectedPosition(int position) {
        selectedPosition = position;
    }
    //每个子项被滚动到屏幕内的时候会被调用
    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        BPA_GOODSRECIPE lc = (BPA_GOODSRECIPE) getItem(position);//得到当前项选中item实例
        //为每一个子项加载设定的布局
        View view = LayoutInflater.from(getContext()).inflate(resource1, parent, false);
        //分别获取 image view 和 textview 的实例

        TextView text = view.findViewById(R.id.text);

        if(lc.processname.equals("液体料"))
        {
            text.setText((new DecimalFormat("00").format(datas.size()- position))
                    +"、"+lc.processname+"     " +lc.processvalue);
        }else
        {
            text.setText((new DecimalFormat("00").format(datas.size()- position))
                    +"、"+lc.processname+"    "+"      " +lc.processvalue);
        }
        return view;
    }
}