Update statement in Realm

前端 未结 2 1731
醉话见心
醉话见心 2021-02-14 05:38

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

VisitingCardPOJO.java

public class VisitingC         


        
2条回答
  •  情书的邮戳
    2021-02-14 06:27

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

提交回复
热议问题