N J N J - 3 months ago 17
Android Question

Update statement in Realm

I have

VisitingCardPOJO
form table I want update single entry say where no=3


VisitingCardPOJO .java


public class VisitingCardPOJO extends RealmObject {

@PrimaryKey private int no;
private String name;
private String address;

public int getNo() {
return no;
}

public void setNo(int no) {
this.no = no;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getAddress() {
return address;
}

public void setAddress(String address) {
this.address = address;
}
}

N J N J
Answer

I found the solution as and It worked

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

see demo for Realm