package com.example.leudaemialikeme.Adapter;

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.example.leudaemialikeme.Model.Event;
import com.example.leudaemialikeme.R;

import java.util.List;

public class EventAdapter extends RecyclerView.Adapter<EventAdapter.ViewHolder>{
    private List<Event> meventList;

    //重写构造方法
    public EventAdapter(List<Event> meventList){
        this.meventList = meventList;
    }
    public int getItemCount(){
        return meventList.size();
    }
    //内部类
    static class ViewHolder extends RecyclerView.ViewHolder {
        TextView event_day,event_month,event_info,event_time;

        public ViewHolder(@NonNull View itemView){
            super(itemView);
            this.event_day = (TextView)itemView.findViewById(R.id.event_day);
            this.event_month = (TextView)itemView.findViewById(R.id.event_month);
            this.event_info = (TextView)itemView.findViewById(R.id.event_info);
            this.event_time = (TextView)itemView.findViewById(R.id.event_time);
        }
    }
    //重写 onCreateViewHolder()方法
    @Override
    public EventAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.event_item,parent,false);
        EventAdapter.ViewHolder holder=new EventAdapter.ViewHolder(view);
        return holder;
    }
    //重写onBindViewHolder()方法
    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder,int position){
        Event event = meventList.get(position);
        holder.event_day.setText(event.getEvent_day());
        holder.event_month.setText(event.getEvent_month());
        holder.event_info.setText(event.getEvent_info());
        holder.event_time.setText(event.getEvent_time());
    }
}
