Skip to content

Notify the ToDoAdapter #1

@RobIsr

Description

@RobIsr

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

No one assigned

    Labels

    help wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions