gpt4 book ai didi

android - 在 Realm 中更新语句

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:51:29 26 4
gpt4 key购买 nike

我有 VisitingCardPOJO 表格。我想更新单个条目说在哪里 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;
}
}

最佳答案

我找到了解决方案并且它有效

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

参见 demo for Realm

关于android - 在 Realm 中更新语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30933229/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com