Adding values from a arrayList to shared Preference

♀尐吖头ヾ 提交于 2019-12-25 02:18:47

问题


Is it possible for me to store and retrieve my ArrayList values using shared preference. Can anyone suggest me with an example.


回答1:


It looks like the closest the SharedPreferences can do is save a Set of Strings. If that doesn't suit you should probably look at the alternatives for persisting data.




回答2:


You can refer to this : http://androidcodemonkey.blogspot.com/2011/07/store-and-get-object-in-android-shared.html (Thanks to Greg Zimmers that give this tutorial).

The idea is you encapsulate the ArrayList to an Object and then you can refer to link tutorial that I give above and follow the tutorial. If you want to retrieve the ArrayList, you can get the Object and then you retrieve the ArrayList from the Object.



来源:https://stackoverflow.com/questions/6274480/adding-values-from-a-arraylist-to-shared-preference

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!