package com.sipai.jspatrol.Fault;

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

import androidx.recyclerview.widget.RecyclerView;

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

import java.util.List;

/**
 * Created by lvliming on 2018/7/22.
 */

public class PSSingleChoiceAdapter extends RecyclerView.Adapter<PSSingleChoiceAdapter.ViewHolder> {
    private Context mContext;
    private List<ProcessSection> list;
    private onRecyclerViewItemClick mOnRvItemClick;

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

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

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

    @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_ps_single_choice_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);
    }
}
