-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Labels
help wantedExtra attention is neededExtra attention is needed
Description
When trying to notify the ToDoAdapter in Main Activity using notifyDataSetChanged() i get no response. My solution so for is to set a new ToDoAdapter on the RecyclerView. The problem is in these two methods:
In MainViewModel:
//This function removes a note from the database and sets a new Adapter with the updated list of notes.
public boolean removeNote(long id) {
//Call mDb.delete to pass in the TABLE_NAME and the condition that WaitlistEntry._ID equals id
mDb.delete(ToDoContract.TodoEntry.TABLE_NAME, ToDoContract.TodoEntry._ID + "=" +
String.valueOf(id), null);
MainActivity.mTodoRecyclerView.setAdapter(new ToDoAdapter(allNotes(), this));
Log.d(TAG, "removeNote: " + "clicked");
return true;
}
and in MainActivity:
/* This function stores the entered text inside the noteEndered String and calls the addNote function in
MainViewModel to get the new list of notes from the allNotesCursor and sets a new Adapter to the
RecyclerView
*/
public void addNoteFromEditText(View view) {
String noteEntered = binding.enterNoteEditText.getText().toString();
viewModel.addNote(noteEntered);
binding.enterNoteEditText.setText("");
mTodoRecyclerView.setAdapter(new ToDoAdapter(viewModel.allNotes(), viewModel));
}
If anyone has an idea about any better way of doing this then I would appreciate the help.
Metadata
Metadata
Assignees
Labels
help wantedExtra attention is neededExtra attention is needed