Convert ForeignCollection to ArrayList - ORMLite, Gson and Android

后端 未结 3 623
悲哀的现实
悲哀的现实 2021-02-01 04:06

I apologize if I\'m not super clear with my explanation but I\'ll add to and edit this question for clarity if requested.

I am developing an Android app which receives d

3条回答
  •  盖世英雄少女心
    2021-02-01 04:26

    You can't create a ForeignCollection other than first storing the objects in the database, then have ormlite retrieve them in the ForeignCollection. You can use a Collection instead of a ForeignCollection, but it works the same way. What I do is the following: I have two collections in the parent class. One is an ArrayList that the json or xml is deserialized into. When the parent object gets stored, the dao stores the objects in the Arraylist to the database, in the table that's linked to the other Collection, a ForeignCollection. When the parent object is retrieved, it automatically contains the objects in the ForeignCollection. It's not perfect, but it works.

提交回复
热议问题