error in recyclerVIew (Collections.reverse)


I have a serious problem making an app. I wanted to make a notepad, I add the notes but I wanted the order of the entry of notes to be the other way around, that is, the last note was the one that was shown first, as it was in a ArrayList notes so use this :

private Note getNote(int position) {
    return notes.get(position);

and I change them well but now there is a problem when executing the app you enter a note well, you enter the second note and the first note takes the value of the second one (as if it had been repeated), you put the third note and it comes out how it should be example


* first note added = a --- is displayed on screen at


** second note added = b --- is displayed on screen b (first note),                                                           b (second note)


* third note added = c --- shown on screen at (first note)                                                          b (second note)                                                          c (third note)

I'm sending you the adapter code:

public class NotesAdapter extends RecyclerView.Adapter<NotesAdapter.NoteHolder> {
    private Context context;
    private ArrayList<Note> notes;
    private NoteEventListener listener;
    private boolean multiCheckMode = false;

    public NotesAdapter(Context context, ArrayList<Note> notes) {
        this.context = context;
        this.notes = notes;

    public NoteHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = LayoutInflater.from(context).inflate(R.layout.note_layout, parent, false);
        return new NoteHolder(v);


    public void onBindViewHolder(NoteHolder holder, int position) {
        int c=notes.size();

        final Note note = getNote(position);
        if (note != null) {
            holder.noteDate.setText(NoteUtils.dateFromLong(note.getNoteDate()));            // init note click event
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                public void onClick(View view) {

            // init note long click
            holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {
                public boolean onLongClick(View view) {
                    return false;

            // check checkBox if note selected
            if (multiCheckMode) {
                holder.checkBox.setVisibility(View.VISIBLE); // show checkBox if multiMode on
            } else holder.checkBox.setVisibility(View.GONE); // hide checkBox if multiMode off


    public int getItemCount() {

        return notes.size();

    private Note getNote(int position) {
        return notes.get(position);

     * get All checked notes
     * @return Array
    public List<Note> getCheckedNotes() {
        List<Note> checkedNotes = new ArrayList<>();
        for (Note n : this.notes) {
            if (n.isChecked())

        return checkedNotes;

    class NoteHolder extends RecyclerView.ViewHolder {
        TextView noteText, noteDate;
        CheckBox checkBox;

        public NoteHolder(View itemView) {
            noteDate = itemView.findViewById(;
            noteText = itemView.findViewById(;
            checkBox = itemView.findViewById(;

    public void setListener(NoteEventListener listener) {
        this.listener = listener;

    public void setMultiCheckMode(boolean multiCheckMode) {
        this.multiCheckMode = multiCheckMode;

(I add that the code is actually taken from a scrapbook tutorial and I'm still not entirely clear about many things, I'm just learning and if I suggest a book, channel or medium to continue studying I'd appreciate it a lot )

asked by Nicolas Martinez 28.09.2018 в 08:26

0 answers