Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update the values in Table using Realm android?

Tags:

android

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.

like image 470
frost Avatar asked May 11 '15 08:05

frost


1 Answers

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();
        }
like image 109
N J Avatar answered Oct 17 '22 20:10

N J