Reputation: 155
Let’s say i have three objects/elements in my realm database:-
When i delete the first element (i.e A) using the methoddeleteFromRealm()
, the positions of the remaining two objects change like this:-
instead of:-
I wanna know why does this happen. Following is my code:-
public void onSwipe(int adapterPosition) {
.
.
realm.beginTransaction();
activity.getReminders().get(adapterPosition).deleteFromRealm(); //activity.getReminders() returns the RealmResults object
realm.commitTransaction();
}
Upvotes: 1
Views: 94
Reputation: 2096
You need to sort your results to keep the order you want. Example from the doc :
result = result.sort("age"); // Sort ascending
result = result.sort("age", Sort.DESCENDING);
https://realm.io/docs/java/latest/#sorting
Upvotes: 1