How can I delete an object by it's index within the table when using Realm with Android? Please, note that the object does not have ID field that I can use to query on it. I know it's index in the table and want to use it for the deletion.
Asked
Active
Viewed 2,180 times
0
-
Possible duplicate of [How to delete object from Realm Database Android?](http://stackoverflow.com/questions/36736178/how-to-delete-object-from-realm-database-android) – Mohammed Atif Apr 03 '17 at 15:19
2 Answers
1
realm.executeTransaction(new Realm.Transaction() {
@Override
public void execute(Realm realm) {
RealmResults<MyObject> result = realm.where(MyObject.class).findAll();
result.deleteFromRealm(index);
}
});

Ousmane D.
- 54,915
- 8
- 91
- 126

Ivo Stoyanov
- 16,256
- 8
- 62
- 65
0
public void deletePerson(int personId, int position) {
RealmResultsresults=null;
results=myRealm.where(context).equalTo("id", personId).findAll();
myRealm.beginTransaction();
results.remove(0);
myRealm.commitTransaction();
personDetailsModelArrayList.remove(position);
personDetailsAdapter.notifyDataSetChanged();
}
Hi ,
I Hope This code will be use full to u.
This followed link is help full to u
http://www.theappguruz.com/blog/realm-mobile-database-implementation-in-android
-
The object does not have ID field that I can use to query on. I know it's index within the table and want to use it for deletion. – Ivo Stoyanov Apr 04 '17 at 07:58