如何保存由 2 个字符串组成的首选项并显示它们?

How to save preferences composed of 2 strings and display them?

我目前正在创建一个 android 应用程序。此应用程序应允许用户输入 RSS 提要 URL 并将其保存为首选项。我知道如何使用 key/value 属性保存基本首选项(字符串、布尔值...)。我的问题是我想将 RSS 提要的 URL 和网站名称保存为一种偏好(例如 http://rss.cnn.com/rss/edition.rss --> CNN 头条新闻)。 所以在这种情况下,一个首选项由 2 个字符串组成,我不知道该怎么做。

我找到了一个 JSON 模块,可以将对象保存为首选项,但我想避免为此应用程序使用任何模块。

是否可以在没有外部模块的情况下做我想做的事情,如果可以,你能帮我解决这个问题吗?

我觉得你想多了。相反,考虑这种方法:

String rssUrl = "someUrlHere";

String rssWebsite = "Some website name here";

//Now, you can use a delimiter before storing your two values 

String rssUrlAndWebsite = rssUrl + "," + rssWebsite;

//Now you can store this using one key. 

//When you want to read them out, you can use your key to get the value and simply split using the delimiter and there, you will have two values!

希望对您有所帮助;

或者,您可以将这两个值存储在 table!