I am new to programming in android and I am working on recycler view adapter for which I am not able to work with the setText() method in the Adapter
public void onBindViewHolder(@NonNull NoteHolder holder, int position) {
NoteModel noteModel = mNoteList.get(position);
holder.tvNote.setText(noteModel.getNote());//Error in this
holder.tvAddedOn.setText(addedON);//Error in this
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm");
String addedON = String.valueOf(dateFormat.format(new Date(noteModel.getAddedOn())));
}
I tried to view all the references which can help me to set the text but not able to find one, is there any other alternative for this??
CodePudding user response:
The Adapter does not know, or rather care, what type of items it contains, meaning editing those items is nothing the adapter does. What it does know however, is the items' id's. You can get those by using getItemId(). You can then use the id to find the respective View and change whatever you need to change there.
CodePudding user response:
Follow the steps:
Just try to Re-arrange it
NoteModel noteModel = mNoteList.get(position); SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm"); String addedON = String.valueOf(dateFormat.format(new Date(noteModel.getAddedOn()))); holder.tvNote.setText(noteModel.getNote());//Put it at the bottom holder.tvAddedOn.setText(addedON);//Put it at the bottom