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.InfoSel;
import com.sipai.jspatrol.R;

import java.util.List;

/**
 * created by lvliming on 2019/7/10
 */
public class SelAdapter extends RecyclerView.Adapter<SelAdapter.ViewHolder> {
    private Context mContext;
    private List<InfoSel> list;
    private onRecyclerViewItemClick mOnRvItemClick;

    public SelAdapter(Context mContext, List<InfoSel> list, onRecyclerViewItemClick mOnRvItemClick) {
        this.mContext = mContext;
        this.list = list;
        this.mOnRvItemClick = mOnRvItemClick;
    }

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

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        InfoSel item = list.get(position);
        holder.tv_name.setText(item.getText());
    }

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

    public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
        View tview;
        TextView tv_name;
        public ViewHolder(View itemView) {
            super(itemView);
            tview = itemView;
            tv_name = itemView.findViewById(R.id.moudle_item_sel_tv_name);
            tview.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);
    }
}
