realm / realm-android-adapters

Adapters for combining Realm Java with Android UI components and framework classes
realm.io
Apache License 2.0
414 stars 134 forks source link

How to know when RealmResults changed? #138

Closed demogorgorn closed 6 years ago

demogorgorn commented 6 years ago

Should we use in activity/fragment RealmResult listener or we can do this using adapter. My case is to ypdate internal counters when item was added to realm.

cmelchior commented 6 years ago

Hi @demogorgorn These sorts of questions are better suited for Stack Overflow that also has a bigger community for answering.

But you want to add a RealmChangeListener to your RealmResults. This is e.g. what our RealmRecyclerViewAdapter does: https://github.com/realm/realm-android-adapters/blob/master/adapters/src/main/java/io/realm/RealmRecyclerViewAdapter.java#L181

If you do it inside an activity or inside an adapter is really up to you as it depends a lot on the use case and general archicture of your app.