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 String
s. 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.