Untitled

mail@pastecode.io avatar
unknown
java
2 years ago
2.4 kB
2
Indexable
Never
package com.maruf.firebasecontarctapps.adapters;

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.bumptech.glide.Glide;
import com.google.android.material.imageview.ShapeableImageView;
import com.maruf.firebasecontarctapps.R;
import com.maruf.firebasecontarctapps.models.StudentModel;

import java.util.ArrayList;
import java.util.List;

public class StudentAdapter extends RecyclerView.Adapter<StudentAdapter.StudentViewHolder> {

    List<StudentModel> studentList = new ArrayList<>();

    public StudentAdapter(List<StudentModel> studentList) {
        this.studentList = studentList;
    }

    @NonNull
    @Override
    public StudentViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {

        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.sample_row,parent,false);

        return new StudentViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull StudentViewHolder holder, int position) {
        StudentModel models = studentList.get(position);
        if (models != null) {
            Glide.with(holder.profileImage.getContext())
                    .load(models.getProfileImg()).placeholder(R.drawable.placeholder)
                    .into(holder.profileImage);
            holder.name.setText(models.getName());
            holder.department.setText(models.getDepartment());
            holder.number.setText(models.getNumber());
        }


    }

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

    public static class StudentViewHolder extends RecyclerView.ViewHolder {
        ShapeableImageView profileImage,edit,delete;
        TextView name,department,number;
        public StudentViewHolder(@NonNull View itemView) {
            super(itemView);

            profileImage = itemView.findViewById(R.id.proImg);
            name = itemView.findViewById(R.id.nameTv);
            department = itemView.findViewById(R.id.departmentTV);
            number = itemView.findViewById(R.id.phoneNumTv);
            delete = itemView.findViewById(R.id.delete);
            edit = itemView.findViewById(R.id.edit);
        }
    }


}