package com.example.writeepc;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.ViewGroup;

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

import com.example.writeepc.databinding.ItemEpcBinding;

import java.util.List;

public class MyAdapter extends RecyclerView.Adapter<MyAdapter.MyViewHoder> {

    private List<String> list;
    private Context context;
    private LayoutInflater inflater;

    public MyAdapter(Context context) {
        this.context = context;
        inflater = LayoutInflater.from(context);
    }

    public void setList(List<String> list) {
        this.list = list;
    }

    @NonNull
    @Override
    public MyViewHoder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        ItemEpcBinding binding = DataBindingUtil.inflate(inflater, R.layout.item_epc, parent, false);
        return new MyViewHoder(binding);
    }

    @Override
    public void onBindViewHolder(@NonNull MyViewHoder holder, int position) {
        holder. binding.setVariable(BR.data,list.get(position));
    }

    @Override
    public int getItemCount() {
        return list == null ? 0 : list.size();
    }

    class MyViewHoder extends RecyclerView.ViewHolder {
        private ItemEpcBinding binding;

        public MyViewHoder(ItemEpcBinding binding) {
            super(binding.getRoot());
            this.binding = binding;
        }

    }
}
