我有RealmObject类,并且在RealmObject中也有RealmList。我尝试在我的RealmList中添加一些数据,但我不能。 这是我的RealObject类
public class VinScannerHistoryModel extends RealmObject {
@Required
private String vinNumber;
@Required
private String userName;
@Required
private String status;
private RealmList<ImagesObject> imagesObjects;
@Required
private String key;
public String getVinNumber() {
return vinNumber;
}
public void setVinNumber(String vinNumber) {
this.vinNumber = vinNumber;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public RealmList<ImagesObject> getImagesObjects() {
return imagesObjects;
}
public void setImagesObjects(RealmList<ImagesObject> imagesObjects) {
this.imagesObjects = imagesObjects;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public String getPolygon() {
return polygon;
}
public void setPolygon(String polygon) {
this.polygon = polygon;
}
@Required
private String polygon;
}
这是一个RealmList类
public class ImagesObject extends RealmObject {
public String getImageName() {
return imageName;
}
public void setImageName(String imageName) {
this.imageName = imageName;
}
private String imageName;
}
我尝试添加一些像这样的值
private void insertIntoDatabase()
{
mRealm.beginTransaction();
ImagesObject imagesObject = mRealm.createObject(ImagesObject.class);
VinScannerHistoryModel vinScannerHistoryModel = mRealm.createObject(VinScannerHistoryModel.class);
vinScannerHistoryModel.setVinNumber(vinNumber.getText().toString());
vinScannerHistoryModel.setStatus("Justsaved");
if(Global.imagePath!=null && Global.imagePath.size()>0)
{
for (int i = 0; i < Global.imagePath.size(); i++) {
imagesObject.setImageName(Global.imagePath.get(i));
}
vinScannerHistoryModel.getImagesObjects().add(imagesObject);
}
if(checkBox.isChecked())
vinScannerHistoryModel.setKey("1");
else
vinScannerHistoryModel.setKey("0");
vinScannerHistoryModel.setPolygon(polygonAdapter.getItem(spinnerPosition).getId()+"");
vinScannerHistoryModel.setUserName(vinScannerModel.getName());
mRealm.commitTransaction();
}