从 Sharedpreferences 中的 Set 中删除特定项目 [英] Remove a specific item from a Set in Sharedpreferences
本文介绍了从 Sharedpreferences 中的 Set 中删除特定项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的 sharedPref 中有一组字符串.我想删除列表中的特定项目
I have a Set of Strings in my sharedPrefs. I would like to remove a specific item in the list
<set name="items">
<string>217372223</string>
<string>222015066</string>
<string>217771052</string>
<string>220431322</string>
所以我只想删除 217372223 但保留其余的?
So I would like to just remove say, 217372223 but keep the rest?
推荐答案
You can use the remove(String key)
method of SharedPreferences.Editor
SharedPreferences sharedPreferences = context.getSharedPreferences("items", Context.MODE_PRIVATE);
sharedPreferences.edit().remove(String key).commit();
确保您的条目有密钥.尝试这样的事情:
Make sure your entry has a key. Try something like this:
<string name="keyToDelete">217372223</string>
然后
sharedPreferences.edit().remove("keyToDelete").commit();
这篇关于从 Sharedpreferences 中的 Set 中删除特定项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文