• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

DiffUtil.calculateDiff In RecyclerView

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have this code below which uses the DiffUtil.calculateDiff between two lists. Each time i scroll further down the list, new data comes and added to the list. But when the result notifies changes, the adapter leads me to the top of the list each time.

1. How can i  remain to the position which the new data was added?
2. This example is the right usage of DiffUtil.calculateDiff?or  simply do i need to use :


without the DiffUtil.calculateDiff.
 
Bartender
Posts: 667
14
TypeScript Fedora
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can make the recyclerview go to a position by using

void scrollToPosition(int position)
Convenience method to scroll to a certain position.
 
Greenhorn
Posts: 18
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For avoiding such cases, make sure:

1. You have complete implementations of and and .
2. Handling for all cases whether you're handling null values or say when a certain kind of item should or shouldn't be refreshed along with returning appropriate results.
3. Avoid object reference checks as they might be different. Only use fine item comparisons - override and write your own implementation.
4. Make sure to always use DiffUtil for any kind of list updations.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic