How to update the values in Table using Realm android?

一曲冷凌霜 提交于 2020-01-22 12:56:05

问题


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.


回答1:


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



回答2:


note that Realm will delete that object if the new data or if input is empty that you want to update .thus why one would see that their data disappearing or getting deleted suddenly.



来源:https://stackoverflow.com/questions/30163244/how-to-update-the-values-in-table-using-realm-android

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!