如何保存对象数组
因此,我正在制作一个问答游戏,因此我创建了一系列自定义问题。我的 raw 文件夹中有一个 xml 文件,其中包含所有问题,并将所有内容解析到我的数组中。我希望能够在用户完成游戏并开始新游戏后重新整理所有问题。
这真的很容易实现——只需打乱数组即可!我遇到的问题是保存东西。通过共享首选项,我可以在关闭应用程序时保存索引(用户所在的问题)。但是,当我对数组进行洗牌时,它们离开应用程序并返回 - 数组又回到默认数组,因此洗牌有点没有实际意义。显然,您无法使用共享首选项保存数组 - 那么有人知道保存打乱数组的简单/简单方法吗?
So, I'm making a trivia game and so I created a custom array of questions. I have an xml file in the raw folder that holds all the questions, and parses everything into my array. I want to have the ability to shuffle all the questions after the user is done with a game and starts a new one.
This is really easy to implement - just shuffle the array! The problem I run into is saving things. With Shared Preferences, I can save the index (question the user was at) when they close the app. But when I shuffle the array, and they leave the app and go back in - the array is back to the default array so the shuffle is kind of moot. You obviously can't save arrays with shared prefs - so does anyone know a simple/easy way to save the shuffled array?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
序列化和 http://developer.android.com/guide/topics /data/data-storage.html#filesInternal
Serialize and http://developer.android.com/guide/topics/data/data-storage.html#filesInternal