How can I edit existing data in realm android DB?


#1

I have a Listview of different Strings. I need to save it to my Realm DB. This Listview can sometimes be changed. So, every time when this activity gets created, I need to update Realm DB if the data has changed. I have created a Model class, see it below.

Model class

public class Allergen extends RealmObject {

    private RealmList<String> objects;


    public RealmList<String> getObjects() {
        return objects;
    }

    public void setObjects(RealmList<String> objects) {
        this.objects = objects;
    }

}

In the onCreate of this activity, how can I save my data to an existing List?

onCreate

Realm realm = Realm.getDefaultInstance();
        realm.beginTransaction();
        Allergen true_items = new Allergen();
        for(int k=0; k<myitems.size(); k++){
            MyItem allergy = myitems.get(k);
            Boolean containAllergy=allergy.isChecked();
            if (containAllergy) {
//                add allergy.getTitle (it's string) to the true_items
            }
        }
        realm.copyToRealm(true_items);
        realm.commitTransaction();
        realm.close();

In the example above, I create new object true_items, but how can I change sth in it later? How can I add this data?