[英]What is the best way to write a setter for RealmList taking in an ArrayList?
Say I have RealmList<ObjectExtendsRealmObject> list;
假设我有RealmList<ObjectExtendsRealmObject> list;
I want to have a setter for this that takes in ArrayList
as a param. 我想要一个将ArrayList
作为参数的设置器。 How do I update the objects in RealmList
with this ArrayList? 如何使用此ArrayList更新RealmList
的对象?
I assume something like 我假设类似
public void setList(ArrayList<ObjectExtendsRealmObject> list) {
if(this.list == null) {
this.list = new RealmList<>(list);
} else {
this.list.clear();
this.list.addAll(list);
}
}
Hi I have used below method to convert my ArrayList to RealmList . 嗨,我已经使用以下方法将ArrayList转换为RealmList 。
public void setList(ArrayList<YourModel> list) {
RealmList<YourModel> realmList=new RealmList<YouModel>(list.toArray(new YouModel[list.size()]));
}
this method is working perfect for me hope this will work for you.If you face any issue please let me know 这种方法对我来说是完美的,希望对您有用。如果您遇到任何问题,请告诉我
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.