Last active
December 5, 2020 07:52
-
-
Save ns-github14/07cc0ba0133761a2e3a688a04fd91bfe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class RVAdapter extends FirestoreRecyclerAdapter<Doctor_Class, RVAdapter.RVViewHolder> { | |
private OnItemClickListener listener; | |
public RVAdapter(@NonNull FirestoreRecyclerOptions<Doctor_Class> options){ | |
super(options); | |
} | |
@Override | |
protected void onBindViewHolder(@NonNull RVViewHolder holder, int position, @NonNull Doctor_Class model){ | |
holder.name.setText(model.getName()); | |
holder.specialization.setText(model.getSpecialization()); | |
holder.hospital.setText(model.getHospital()); | |
} | |
@NonNull | |
@Override | |
public RVViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { | |
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.cardview_doctor, parent, false); | |
return new RVAdapter.RVViewHolder(view); | |
} | |
class RVViewHolder extends RecyclerView.ViewHolder { | |
TextView name, specialization, hospital; | |
public RVViewHolder(@NonNull View itemView) { | |
super(itemView); | |
name = itemView.findViewById(R.id.name); | |
specialization = itemView.findViewById(R.id.specialization); | |
hospital = itemView.findViewById(R.id.hospital); | |
itemView.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
int position = getAdapterPosition(); | |
if (position != RecyclerView.NO_POSITION && listener != null) { | |
listener.onItemClick(getSnapshots().getSnapshot(position), position); | |
} | |
} | |
}); | |
} | |
} | |
public interface OnItemClickListener { | |
void onItemClick(DocumentSnapshot documentSnapshot, int position); | |
} | |
public void setOnItemClickListener(OnItemClickListener listener) { | |
this.listener = listener; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment