对自定义对象的数组列表存储 [英] Store Arraylist of cutom objects

查看:228
本文介绍了对自定义对象的数组列表存储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在共享preferences像这样保存的自定义对象的ArrayList

I have saved ArrayList of custom objects in the shared preferences like this:

SharedPreferences prefs = context.getSharedPreferences("prefName", Context.MODE_PRIVATE);
Editor editor = prefs.edit();
editor.putStringSet("myList", new Gson().toJson(arraylist).toString());
editor.apply();  

通过从应用程序这样做,一旦价值被保存,但是当我退出并重启并尝试保存新的值,然后将旧值都没有了。结果
任何想法我怎么能保存旧的值并追加新的结果?
我想保留的所有值在同一阵列中,并保持保存值显示每次阵列时,应用程序加载。

By doing this, once values are saved but when i exit from the app and relaunch and try to save new values then the old values are gone.
Any idea how can i save old values and append new ones??
I want to keep all values in the same array and keep array saved to show values everytime when the app loads.

推荐答案

myList中 prefName ,追加的ArrayList 什么是已经保存在preferences,回写 myList中来preferences。

Read myList from prefName, append arraylist to what was already saved in the preferences, write back myList to preferences.

这篇关于对自定义对象的数组列表存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆