Here is the code I used in my RecycleView
adapter class. I don\'t know this is the right way or not to use View Binding. If you have a better solution answer me. Th
Here is full recycler view adapter class in java :
public class NotesAdapter extends RecyclerView.Adapter {
private List notes;
private ItemNotesBinding notesBinding;
public NotesAdapter(List notes) {
this.notes = notes;
}
@NonNull
@Override
public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
notesBinding = ItemNotesBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);
return new MyViewHolder(notesBinding);
}
@Override
public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
Note note = notes.get(position);
notesBinding.tvTitle.setText(note.getNote());
}
@Override
public int getItemCount() {
return notes.size();
}
public static class MyViewHolder extends RecyclerView.ViewHolder {
ItemNotesBinding notesBinding;
public MyViewHolder(@NonNull ItemNotesBinding binding) {
super(binding.getRoot());
notesBinding = binding;
}
}
}