Toggle auto update in adapter
sandeshlasnapure opened this issue · 6 comments
Is there any way to disable autoupdate?
In my case I have a ViewPager wich has 5 tabs attached to it, and I am using same adapter for all with different query params.
Now I want to disable the autoupdate if fragment is not visible.
Thanks.
are you using RealmBaseAdapter
or RealmRecyclerViewAdapter
?
RealmBaseAdapter
register internally a listener to notify the data set change.
with RealmRecyclerViewAdapter
you can set the boolean on false
when calling the constructor to disable the internal listener (autoUpdate)
I am using RealmRecyclerViewAdapter. While calling constructor I am setting update param true, but if fragment is no longer visible to user I don't want to update my list.
or should I use RealmBaseAdapter instead?
If you're using the same RealmRecyclerViewAdapter
then I suppose you're calling updateData
to use the RealmResults
query that correspond to this View/Fragment. The call to updateData
will remove the previous listener, so only the current Fragment/View using the adapter will receives notifications. Same with RealmBaseAdapter
.
That being said, be careful with the ViewPager, as it needs to build the offscreen previous/after which will end up trying to reuse the same RealmRecyclerViewAdapter
for 3 different Fragments, which is not what you want I guess, since the previous, current and next screen will all use the same data.
Why not use a dedicated RealmRecyclerViewAdapter
/ RealmBaseAdapter
per page, then limit the number of offscreen pages the ViewPager tries to build using setOffscreenPageLimit
?
I am passing the realm result in constructor.
I think creating dedicated adapter would be fine as of now.
But again will it leads to performance issue?
I have implemented dedicated adapters and no noticeable performance issue, will go with it.
Thanks.