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();
}
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);