Untitled
unknown
plain_text
a year ago
2.8 kB
3
Indexable
Never
package com.example.managerstaff.adapter; import android.app.Activity; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.TextView; import androidx.annotation.NonNull; import androidx.constraintlayout.widget.ConstraintLayout; import androidx.recyclerview.widget.RecyclerView; import com.example.managerstaff.R; import com.example.managerstaff.models.Calendar; import com.example.managerstaff.models.StatisticalTimeUser; import java.util.List; public class CalendarAdapter extends RecyclerView.Adapter<CalendarAdapter.TimeKeepingViewHolder> { private Activity mActivity; private List<Calendar> listCalendars; private int idUser=0; public CalendarAdapter(Activity mActivity) { this.mActivity = mActivity; } public void setData(List<Calendar> listCalendars){ this.listCalendars=listCalendars; notifyDataSetChanged(); } public void setIdUser(int idUser){ this.idUser=idUser; } @NonNull @Override public TimeKeepingViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.item_calendar,parent,false); return new TimeKeepingViewHolder(view); } @Override public void onBindViewHolder(@NonNull TimeKeepingViewHolder holder, int position) { Calendar calendar =listCalendars.get(position); if(calendar!=null){ holder.txtTimeStart.setText(calendar.getTimeStart()); holder.txtTimeEnd.setText(calendar.getTimeEnd()); holder.txtHeader.setText(calendar.getHeaderCalendar()); holder.txtBody.setText(calendar.getBodyCalendar()); holder.layout_item.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { } }); } } @Override public int getItemCount() { if(listCalendars!=null) return listCalendars.size(); return 0; } public class TimeKeepingViewHolder extends RecyclerView.ViewHolder{ private ConstraintLayout layout_item; private TextView txtTimeStart,txtTimeEnd,txtHeader,txtBody; public TimeKeepingViewHolder(@NonNull View itemView) { super(itemView); layout_item=itemView.findViewById(R.id.layout_item_calendar); txtTimeStart=itemView.findViewById(R.id.txt_time_start); txtTimeEnd=itemView.findViewById(R.id.txt_time_end); txtHeader=itemView.findViewById(R.id.txt_header_calendar); txtBody=itemView.findViewById(R.id.txt_body_calendar); } } }