Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update statement in Realm

Tags:

android

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;
    }
}
like image 512
N J Avatar asked Jun 19 '15 08:06

N J


1 Answers

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

like image 143
N J Avatar answered Oct 11 '22 09:10

N J