Search code examples
androidandroid-recyclerviewrealm-java

Realm DB & RecyclerView timing issue while deleting items


The setup: (project link)

I use a RecyclerView (with a RealmRecyclerViewAdapter) showing a List of names, which looks like this.

In order to manage the View of the sticky index letter in the top left corner vs the index letter of the item itself, a ScrollListener on the RecyclerView sets the visibility of the sticky index and the item's index via updateStickyIndex().

The problem:

Whenever I delete something in the Realm DB, updating the sticky index in onSuccess() of the RealmTransaction will execute before the items have actually changed on the RecyclerView. In order to call updateStickyIndex() after the items have changed, I have to delay the call in onSuccess().

What am I missing?


Solution

  • By overriding onLayoutCompleted() of the LinearLayoutManager (got his from here) the update of the sticky index can be called at the correct moment (after the LayoutManager has actually finished the changes in the DB/Adapter).