Skip to content Skip to sidebar Skip to footer

How To Update The Values In Table Using Realm Android?

I have table say Student .I want to updated the values in the table and it does not have any primary key. I am using Realm Database for the same.

Solution 1:

Assume You have VisitingCardPOJO you can find element depending on "no" use findFirst() if you want to update only first element or you can use findAll() you get list of record then you update same way below using for loop

publicvoidupdateNewCard(Realm realm, VisitingCardPOJO card) {
            VisitingCardPOJO toEdit = realm.where(VisitingCardPOJO.class)
                    .equalTo("no", card.getNo()).findFirst();
            realm.beginTransaction();
            toEdit.setName(card.getName());
            toEdit.setAddress(card.getAddress());
            realm.commitTransaction();
        }

Solution 2:

note that Realm will delete that object if the new data or if input is empty that you want to update .thus why one would see that their data disappearing or getting deleted suddenly.

Post a Comment for "How To Update The Values In Table Using Realm Android?"