I have VisitingCardPOJO
form table. I want update single entry say where no=3
VisitingCardPOJO.java
public class VisitingC
I found the solution as and It worked
public void updateNewCard(Realm realm, VisitingCardPOJO card) {
realm.beginTransaction();
VisitingCardPOJO toEdit = realm.where(VisitingCardPOJO.class)
.equalTo("no", card.getNo()).findFirst();
toEdit.setName(card.getName());
toEdit.setAddress(card.getAddress());
realm.commitTransaction();
}
see demo for Realm
The actual right way to do it is this
public void updateNewCard(Realm realm, VisitingCardPOJO card) {
final int no = card.getNo();
realm.executeTransaction(new Realm.Transaction() {
@Override
public void execute(Realm realm) {
VisitingCardPOJO toEdit = realm.where(VisitingCardPOJO.class)
.equalTo("no", no).findFirst();
if(toEdit != null) {
toEdit.setName(card.getName());
toEdit.setAddress(card.getAddress());
}
}
});
}