gpt4 book ai didi

Android - 将领域列表保存在领域对象中

转载 作者:行者123 更新时间:2023-11-29 00:03:39 24 4
gpt4 key购买 nike

我有一个模型

public class Response extends RealmObject {

@PrimaryKey
private String _id;
private RealmList<TaskResponse> task_responses;
private AssignmentRecord assignmentRecord;
private ResponseStatistic responseStats;
}

现在,我试图在 Response 中保存 task_responses realmlist 但没有成功,下面是相关代码:

    mRealm.beginTransaction();
response.setTaskResponses(taskResponses);
response.setAssignmentRecord(assignmentRecord);
response.setResponseStats(responseStatistic);
mRealm.commitTransaction();

当我把调试器放在这一行之前

response.setTaskResponses(taskResponses);

taskResponses 的大小是 5,但在执行后它变为空并且 realm 存储一个空列表。

任务响应模型:

    public class TaskResponse extends RealmObject {

@PrimaryKey
private String _id;
private String taskId;
private Boolean answered;
private String answer;
private TaskStatistic taskStat;
}

最佳答案

你可以像这样保存它会起作用

Realm mRealm = Realm.getDefaultInstance();
mRealm.beginTransaction();
RealmList<TaskResponse> taskResponseslist = new RealmList();
taskResponseslist.addAll(taskResponses);
response.setTaskResponses(taskResponseslist);
response.setAssignmentRecord(assignmentRecord);
response.setResponseStats(responseStatistic);
mRealm.commitTransaction();
mRealm.close();

关于Android - 将领域列表保存在领域对象中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43450479/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com