DiffUtil ItemCallback areContentsTheSame() always returns true after updating an item on the ListAdapter

前端 未结 4 614
灰色年华
灰色年华 2020-12-18 04:13

While using a ListAdapter I noticed that after updating an item the DiffUtil.ItemCallback areContentsTheSame() method was always returning true. De

4条回答
  •  死守一世寂寞
    2020-12-18 04:41

    I spent a lot of time until I found out that I was having the same issue as described on this post. I tried many solutions, but in the end I realised that I was messing it up without knowing. If you're having this same issue, check if you aren't updating the UI first and calling a write command to update the value on your repository. In my case, I was updating the LiveData object and then updating that value on Firebase Database. The issue was being caused because my UI was listening to changes on that LiveData object, so my Firebase Database observer detected changes, the ListAdapter was called and it looked like nothing has been changed.

    To solve the problem, I dropped the lines that were updating the LiveData object and I only called Firebase Database sending the changes.

提交回复
热议问题