Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 使用SharedReferences存储和获取数据_Android_Arrays_String_Url_Sharedpreferences - Fatal编程技术网

Android 使用SharedReferences存储和获取数据

Android 使用SharedReferences存储和获取数据,android,arrays,string,url,sharedpreferences,Android,Arrays,String,Url,Sharedpreferences,我想从string.xml中存储和调用用户最喜欢的链接我该怎么做 我想澄清的是,用户只需输入最喜欢的url的名称,例如,它将与用户当前在我的应用程序(例如www.sport.com)上查看的页面相关联 my string.xml <?xml version="1.0" encoding="utf-8"?> <resources> <string name="app_name">MyApp</string> <string-ar

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

我想澄清的是,用户只需输入最喜欢的url的名称,例如,它将与用户当前在我的应用程序(例如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>

编辑:我在这里找到了解决方案:

你读过这些例子了吗


如果您需要存储比简单首选项更复杂的内容,您可能应该将这些内容存储到一个存储库中。

您到底想要什么?请准确地写下您的问题-1,因为没有搜索如何使用SharedReferences。我已经阅读了更多示例,但都是从资源文件中检索单个字符串,而不是数组字符串,因此无法很好地解决我的问题。我的问题略有不同,因为我不知道要检索的url的数量以及它们的名称,我找不到一个只检索字符串数组且名称为常量的字符串的示例。我不确定我是否完全理解您的问题,但我已修改了我的答案以尝试解决它。
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
}