Skip to content

Notify the ToDoAdapter #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
RobIsr opened this issue Jan 10, 2018 · 0 comments
Open

Notify the ToDoAdapter #1

RobIsr opened this issue Jan 10, 2018 · 0 comments
Labels
help wanted Extra attention is needed

Comments

@RobIsr
Copy link
Contributor

RobIsr commented Jan 10, 2018

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.

@RobIsr RobIsr added the help wanted Extra attention is needed label Jan 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant