如何在 kotlin 的 SharedPreferences 中保存带有布尔值的列表?
我想用布尔值将此列表保存在 SharedPreferences 中:
val listTheme = mutableListOf( false,false,true,false)
如何做到这一点?在 Android Studio 中使用 kotlin 语言
I want to save this list in SharedPreferences with Boolean values:
val listTheme = mutableListOf( false,false,true,false)
how can this be done? in kotlin language in android studio
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 kotlin serialialial serialialization 将数据结构(包括类和列表)存储为JSON字符串 - 还有其他库。但是,对于这样简单的事情,您可能可以自己动手做:
然后,您可以将其扔进字符串的偏好中,然后在以后获取时将其转换回列表。
You can use the Kotlin Serialization library to store data structures (including classes and lists) as JSON strings - there are other libraries too. But for something simple like this, you can probably get away with doing it yourself:
Then you can just throw it in a String preference, and convert it back to a list when you fetch it later.