putStringSet()SharedPreferences

时间:2018-04-30 17:02:24

标签: java android arrays sharedpreferences

我有三个用户输入的输入,我需要将这些数据保存在他的手机中,我首先考虑将其保存为数组,所以当我想要它时,我可以有一个Id,但我搜索过并且每个人都使用这个PutStringSet,我做了一些研究,但没有找到任何可以帮助我如何使用SharedPreferences的人。 感谢...

1 个答案:

答案 0 :(得分:1)

假设您已经在数组中使用了字符串,您只需要:

DECLARE @to_allocate int = 92;
DECLARE @allocated int = 4;

WITH result
AS
(
    SELECT 
        ts,
        points,
        SUM(points) OVER(ORDER BY ts) AS total
    FROM audits
),
points
AS
(
    SELECT 
        ts,
        points,
        total,
        CASE 
            WHEN @to_allocate > total - @allocated THEN total - @allocated
            ELSE @to_allocate - SUM(total - @allocated) 
                                OVER(ORDER BY ts ROWS BETWEEN UNBOUNDED PRECEDING AND 1 PRECEDING)
        END as result
    FROM result
)
SELECT * FROM points
WHERE result > 0;

然后检索它:

Set<String> mySet = new HashSet<String>(Arrays.asList(myArray));
sharedPreferences.edit().putStringSet(myKey, mySet).apply();