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.