使用SharedPreferences存储和获取数据

时间:2011-11-02 16:55:29

标签: android arrays string url sharedpreferences

我想从string.xml存储和调用用户最喜欢的链接,我该怎么做?

我想澄清一下,用户只输入收藏网址的名称,例如,体育活动它将与用户当前在我的应用上查看的网页相关联(例如www.sport.com)

my string.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="app_name">MyApp</string>
    <string-array name="Name_Fav"></string-array>
    //Here I would like to store the names of url favorites
    //<item >Sport</item>
    <string-array name="Url_Fav"></string-array>
    //Here I would like to store full url
    //<item >www.sport.com</item>
</resources>

在我的活动中

public void onClick(View v) {
String[] name_url = //Items retrieved from Name_Fav (sport)
String[] url_fav = //items retrieved from Url_FAv (www.sport.com)
//now here I would like to put and retrieve the data from the resource file
}

编辑:我在这里找到了解决方案: Store a List or Set in SharedPreferences

1 个答案:

答案 0 :(得分:1)

您是否阅读了示例here

如果您需要存储比简单首选项更复杂的内容,您应该将这些内容存储到database