Faisal Shaikh
Faisal Shaikh

Reputation: 4147

How to update the data in Sugar ORM?

I am able to successfully iterate the list which i got from following code:

List<MessageDB> messageDBList = MessageDB.find(MessageDB.class, "read = 0 and m_from = " + StaticMember.CHAT_WINDOW_BUDDY_USER_ID);

This is a code to iterate my list:

for (int i = 0; i < messageDBList.size(); i++) {
    list.add(new com.example.admin.chatsdk.Message("", messageDBList.get(i).getMessage(), "", messageDBList.get(i).getSent() + ""));
    customAdapter.notifyDataSetChanged();
}

But I am not able to set the data for each row. I want to change the data of column named 'read' which I used earlier.

Upvotes: 0

Views: 2269

Answers (1)

Faisal Shaikh
Faisal Shaikh

Reputation: 4147

Here is the solution:

for (int i = 0; i < messageDBList.size(); i++) {
    list.add(new com.example.admin.chatsdk.Message("", messageDBList.get(i).getMessage(), "", messageDBList.get(i).getSent() + ""));

    /*Solution Part*/
    MessageDB messageDB = messageDBList.get(i);
    messageDB.read = 1;
    messageDB.save();
    /*Solution Part*/
}
customAdapter.notifyDataSetChanged();

Upvotes: 1

Related Questions