如何使用Realm Android更新Table中的值? [英] How to update the values in Table using Realm android?

查看:62
本文介绍了如何使用Realm Android更新Table中的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表,说学生.我想更新表中的值,它没有任何主键. 我正在使用Realm数据库.

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.

推荐答案

假设您拥有VisitingCardPOJO,则可以根据"no" 查找元素,如果只想先更新,请使用findFirst()元素,或者您可以使用findAll()来获取记录列表,然后使用for循环

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

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 Android更新Table中的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆