字符串的共享preferences阵列 [英] Array of strings in SharedPreferences

查看:139
本文介绍了字符串的共享preferences阵列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有可能存储的字符串数组中的共享preferences 。在我的应用程序,我想,设置名称进行存储。我知道这可以通过使用数据库来完成,我只是想知道是否有可能,以拯救那些设置的名称作为字符串中的共享preferences阵列

I wanna know whether is it possible to store array of string in the SharedPreferences. In my application i want , set of names to be stored. I know this can be done using DB,i just wanna know whether is it possible to save those set of name as array of strings in the SharedPreferences.

推荐答案

您可以在API级别11和更高的使用共享preferences 商店设置字符串。请参阅<一href="http://developer.android.com/reference/android/content/Shared$p$pferences.html#getStringSet%28java.lang.String,%20java.util.Set%3Cjava.lang.String%3E%29"><$c$c>getStringSet()和<一href="http://developer.android.com/reference/android/content/Shared$p$pferences.Editor.html#putStringSet%28java.lang.String,%20java.util.Set%3Cjava.lang.String%3E%29"><$c$c>putStringSet()ю

You can store set of String using SharedPreferences in API Level 11 and higher. See getStringSet() and putStringSet()ю

在API级别前11,你可以使用一些黑客。例如,如果你需要存储在密钥字符串数组的字符串数组的,你可以使用保存每个字符串由数组 putString 键,按键的 stringArray.1stringArray.2的,等等。

In API Level prior to 11 you can use some kind of hack. For example, if you need to store string array under key "stringArray", you can save each string from array using putString and keys "stringArray.1", "stringArray.2", so on.

这篇关于字符串的共享preferences阵列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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