I'm new to Android development, and I also don't know English very well, I apologize in advance.
I'm developing a notepad. I have two Recycleviews, the first one displays labels and the second one displays notes. For development, I use the MVP pattern, as well as Room.
When the activity starts, I get all the notes from the repository, namely notesDao (LiveData<List>), and sign them in the activity.
public void settingsNotesList(LiveData<List<Note>> noteList) {
mActivityBinding.listNotes.addItemDecoration(new SpacesItemDecoration(15));
mActivityBinding.listNotes.setLayoutManager(gridLayoutManager);
mNoteAdapter = new GenericNoteAdapter<>(new DiffUtilNote(),
R.layout.item_note,
(binder, model) -> {
binder.setNote(model);
mActivityBinding.executePendingBindings();
});
mActivityBinding.listNotes.setAdapter(mNoteAdapter);
noteList.observe(this, notes -> {
mNoteAdapter.submitList(notes);
});
}
How can I correctly update the list of notes so that when you click on a label, it shows the notes marked with this label?
I implemented it like this: We create MutableLiveData in the repository, and assign it ListNotes (a list of all notes), and when you click on the label for MutableLiveData, a new list is assigned via (setValue) with the necessary notes and MutableLiveData itself has been mastered the observe observer.
This works, but there is one thing, but if you delete a note or add a new one, the list is not updated and notes are not deleted / added. This is probably due to the fact that from notesDao (room), I get lists of notes List, and not LiveData.
(I tried without switching labels, remove MutableLiveData, and just sign LiveData, then changes occur)
What do you advise? Previous