【发布时间】:2011-11-02 16:55:28
【问题描述】:
我想从 string.xml 中存储和调用用户最喜欢的链接,我该怎么做?
我想澄清一下,用户只为最喜欢的 url 输入一个名称,例如,体育它将与用户当前在我的应用程序上查看的页面相关联(例如 www.sport.com)
我的字符串.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 不搜索如何使用 SharedPreferences。
-
我已经阅读了更多示例,但所有示例都从资源文件中检索单个字符串而不是数组字符串,因此不能很好地解决我的问题
标签: android arrays string url sharedpreferences