0

I'm trying to implement swipe to archive note in RecyclerView.
It was working fine but after I added these codes to refresh the RecyclerView from onResume(), Swiping although does archive the Note, but the item doesn't get removed and stays at a state you can see in image below:

enter image description here

This is what I do in onResume() :

@Override
    protected void onResume() {
        super.onResume();
        notes = noteDAO.getAllNotes();
        noteAdapter = new NoteAdapter(notes,this);
        recyclerView.setAdapter(noteAdapter);
    }  

ItemTouchHelper onSwiped():

@Override
    public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction) {
        int position = viewHolder.getAdapterPosition();
        noteAdapter.deleteItem(position,rv);
    }  

deleteItem method in Adapter:

    public void deleteItem(int position, RecyclerView rv) {
            noteDAO = DBInjector.provideNoteDao(context);
            recentlyDeletedNote = notes.get(position);
            recentlyDeletedNotePosition = position;
            recentlyDeletedNote.setArchive(true);
            notes.remove(position);
            noteDAO.archiveNote(recentlyDeletedNote);
            notifyItemRemoved(position);
    }
Hamed
  • 459
  • 4
  • 20

1 Answers1

0

I have tried a lot of solutions, the only reason why it is not updating the view is that on updating recycler views, views are getting updated especially when ItemTouchHelper is used. As I didn't have much choice I used

recreate()

function for refreshing the whole activity and the error went off.

PS: This is not the ideal solution, it is just workaround fix.

Parthan_akon
  • 219
  • 3
  • 10