1

Every time content is added to the recyclerview and it happens the title is misspelled when I go to fix the mistake, the update/edit does not take effect.

The goal is fixing the update error so when I go back to fix it, the content title would be updated

companion object
{  
//THIS THE ADAPTER CLASS
    private val DIFF_CALLBACK: DiffUtil.ItemCallback<Book> = object:DiffUtil.ItemCallback<Book>()
    {
        @Override
        override fun areItemsTheSame(oldItem: Book, newItem: Book):Boolean
        {
            return oldItem.id == newItem.id
        }

        @Override
        override fun areContentsTheSame(oldItem: Book, newItem: Book): Boolean
        {
            return oldItem.title == newItem.title &&
                    oldItem.author == newItem.author &&
                    oldItem.genre == newItem.genre

        }
    }
}

//THIS IS IN THE MAINACTIVITY
val adapter = BookAdapter()
recyclerView.adapter = adapter 

bookViewModel = 
ViewModelProviders.of(this).get(BookViewModel::class.java)
bookViewModel.getAllBooks().observe(this, object:Observer<List<Book>>
{
     @Override
     override fun onChanged(@Nullable books: List<Book>)
     {
         adapter.submitList(books)
     }
})

I expect the contents in the recyclerview to be updated if I want to fix the error which was misspelled.

  • did you find any better solution? I am stuck at the same problem, I am changing on list position values but observe didn't call. – iamkdblue Feb 08 '20 at 17:00

1 Answers1

-2
adapter.notifyDataSetChanged();

This worked in Java, but don't know kotlin syntax. Try adding this in onChange() method after

adapter.submitList(books)
Md Shahbaz Ahmad
  • 345
  • 4
  • 12