简体   繁体   English

如何使用Realm android更新Table中的值?

[英]How to update the values in Table using Realm android?

I have table say Student .I want to updated the values in the table and it does not have any primary key. 我有表说学生 。我想更新表中的值,它没有任何主键。 I am using Realm Database for the same. 我正在使用Realm数据库。

Assume You have VisitingCardPOJO you can find element depending on "no" use findFirst() if you want to update only first element or you can use findAll() you get list of record then you update same way below using for loop 假设你有VisitingCardPOJO你可以找到依赖于“no”的元素使用findFirst()如果你只想更新第一个元素或者你可以使用findAll()你得到记录列表然后你使用for循环更新相同的方式

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

请注意,如果要更新的新数据或输入为空,Realm将删除该对象。为什么会看到他们的数据消失或突然被删除。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM