package com.sipai.jspatrol.Equ;

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

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.sipai.jspatrol.Bean.EquList;
import com.sipai.jspatrol.R;

import java.util.List;

/**
 * created by lvliming on 2019/7/11
 */
public class PertainToEquSelAdapter extends RecyclerView.Adapter<PertainToEquSelAdapter.ViewHolder> {
    private List<EquList> list;
    private Context context;
    private onRecyclerViewItemClick mOnRvItemClick;

    public PertainToEquSelAdapter(List<EquList> list, Context context, onRecyclerViewItemClick mOnRvItemClick) {
        this.list = list;
        this.context = context;
        this.mOnRvItemClick = mOnRvItemClick;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item ,parent,false);
        final ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        EquList item = list.get(position);
        holder.tv_name.setText(item.getEquipmentname());
        holder.tv_cardId.setText(item.getEquipmentcardid());
    }

    @Override
    public int getItemCount() {
        return list.size();
    }


    public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
        TextView tv_name,tv_cardId;
        View root;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            root = itemView;
            tv_name = itemView.findViewById(R.id.name);
            tv_cardId = itemView.findViewById(R.id.info);
            root.setOnClickListener(this);
        }

        @Override
        public void onClick(View v) {
            if (mOnRvItemClick != null)
                mOnRvItemClick.onItemClick(v, getAdapterPosition());
        }
    }

    /**
     * item点击接口
     */
    public interface onRecyclerViewItemClick {
        void onItemClick(View v, int position);
    }
}
