- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在我的应用中,我有一个方法接受 ID 的 ArrayList
并返回属于这些 ID 的机器的 RealmList
。
public RealmList<Machine> getMachinesById(ArrayList<Long> machineIds) {
RealmList<Machine> machines = new RealmList<Machine>();
for (int i = 0; i < machineIds.size(); i++){
Machine m = getMachineById(machineIds.get(i));
if (m != null) {
machines.add(m);
}
}
return machines;
}
getMachineById()
函数只是查找特定 ID 的正确机器。
我想进一步过滤此输出,但是,当我尝试通过执行 .where()
获取 RealmQuery
时,我收到一个异常,告诉我应该将此 RealmList
置于“托管模式”。
Caused by: io.realm.exceptions.RealmException: This method is only available in managed mode
at io.realm.RealmList.where(RealmList.java:425)
我知道收到此错误是因为此列表是独立的,并且不受 Realm 管理。
可能需要补充的是,此函数将被多次调用,因为每次我的应用程序中的某些列表刷新时都会触发它。这意味着(如果可能的话)每次我创建新的托管 RealmList 时。
我的问题:
最佳答案
Is there any way to let this RealmList be managed by Realm?
是的。有。但拥有 RealmList
的要点是它应该是 RealmObjects
的字段。例如:
public class Factory {
RealmList<Machine> machineList;
// setter & getters
}
Factory factory = new Factory();
RealmList<Machine> machineList = new RealmList<>();
// Add something to the list
factory.setMachines(machineList);
realm.beginTransaction();
Factory managedFactory = realm.copyToRealmOrUpdate(factory);
realm.commitTransaction();
托管表示已持久化Realm。
If this is possible, is it a problem that this function is being called pretty often
视情况而定,如果您不需要再次保留它们,请参阅答案 3。
Is there any other (preferred) way to achieve this (List of IDs > RealmResults/RealmQuery)
就您而言,也许您可以使用 ReaulResults
代替?例如:
RealmQuery<Machine> query = realm.where(Machine.class);
for (int i = 0; i < machineIds.size(); i++){
if (i != 0) query = query.or();
query = query.equalTo("id", machineIds.get(i));
}
RealmResults<Machine> machines = query.findAll();
关于java - 在 RealmObject 外部创建托管 RealmList,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37162444/
我想知道是否有直接的方法来查询 realmObjects 的 realmList 等于另一个 realmList。 例子: public class Tags extends RealmObject{
抱歉,如果问题不是很清楚。让我尝试在这里发展。这是我的结构。 public class User extends RealmObject{ ... RealmList userTags; }
我正在使用 Realm 使用 Realm 创建我的 Android 应用程序的 ORM。问题是当我尝试创建这样的对象时: public class Airport extends RealmObjec
我正在尝试从服务器 (JSON) 中获取 RealmList 的 RealmList 到 Realm 对象中。我得到了 error: Element type of RealmList must be
我的 JSON 数据从服务器 api 看起来像这样 { //... PredecessorIds:[[1,2][3,4][5]] //... } 我可以通过 RealmList 成功处理
我有 3 个 Realm 对象 public class Portfolio extends RealmObject { @PrimaryKey public long id;
我只是想知道是否有一种方法可以在 Android 上对 RealmList 进行异步排序。 假设我有一个名为 diaryEntry 的 Realm 对象,其中包含 Entry 对象的 RealmLis
是否可以将独立对象添加到已经存在于 Realm 中的 RealmObject 的 RealmList 中? 好吧,我知道它不起作用,因为我在 (object.row.getIndex():RealmL
我正在开发一个商店应用程序,每个用户都可以在其中销售商品,也可以将其他用户销售的商品添加到他的愿望 list 中。 现在在用户个人资料中,我想显示他添加到他的愿望 list 中的所有项目。 我的类(c
我刚开始在我当前的 Android 应用程序中使用 Realm,到目前为止它很棒。不幸的是我遇到了一个问题: 在我的应用程序中,用户可以在他的日记中添加不同类型的条目(他今天吃了什么?他喝了什么饮料?
我试图在 forEach 循环中访问模型类的 RealmList。 尝试:1 realmList.forEach(obj -> { System.out.println("value"+obj.get
今天我搬到了Realm 0.83,很高兴我们有 null 支持,但我有一个问题。 我想获取所有产品列表为空的商店。到目前为止,如果我在 RealmQuery 上使用 isNull() 就可以正常工作,
我已经开始使用 Realm,我很好奇是否可以通过嵌套属性对 RealmList 对象进行排序。 我有一些 ListModel 对象: public class ListModel extends Re
我有一个 Person 对象,它有一个电话号码的 RealmList。如何通过电话号码搜索某人?我正在为我的 Android 项目使用 Realm。这是我的模型: class Person exten
我必须定义对象,一个是具有两个字符串和一个 boolean 值的基本 RealmObject,另一个只是该对象的 RealmList,以便于访问。当我尝试从我的 ContactBook 实例获取列表并
我需要在 Realm 模型中实现 Parcelable 接口(interface),但我不知道如何在 Parcel 中编写 RealmList 这是我的代码: public class SomeMod
在我的应用中,我有一个方法接受 ID 的 ArrayList 并返回属于这些 ID 的机器的 RealmList。 public RealmList getMachinesById(ArrayList
我有一个名为 RealmObject 的 A,它包含在 RealmObjects B 和 C 的 RealmList 中. B 和C 都具有多对多 关系。 我如何从 B 中的 RealmList 中删
当我尝试向 Android Realm 数据库中的 RealmList 添加新对象时遇到问题。我总是在以下位置收到 NullPointer 错误: Global.USER_LOGGED.getProd
我想在 RealmBaseAdapter 中使用 RealmList 但它只接受 RealmResult。如何将 RealmList 转换为 RealmResult? 最佳答案 目前你必须做这样的事情
我是一名优秀的程序员,十分优秀!