Search code examples
androidrealm

Deleting a Realm object bound to ListView on Android Studio


I have been working with Android Studio and Realm to create an app for chess noting. The thing is that whenever I delete a 'Game' (Class I created) the last one in the list takes the place of the deleted one (i.e. ListView with "Games" 'a' through 'h', I delete Game 'c', then Game 'h' takes the place of the 'c') and I'd like to know if anyone has had the same problem and how did you solve it. Thanks!


Solution

  • Data in Realm is unsorted by default and we do not give any guarantees about the position if you do not provide a sorting. What you are seeing is actually the expected behavior in the case where you delete data as we will take the last item and put it into the now empty spot (to avoid null values in our internal data structure).

    Using findAllSorted() instead of findAll() should fix it.