我使用以下方法创建了 SharedPreference obj: 注意:在相同的 pref 文件名下创建多个首选项
public static Sting name = "abx"; //pref file name
spo = context.getsharedpreference(name , mode_private);
editor = spo.edit(); //get the editor associated with pref obj
Map<String, String> test= new HashMap<String, String>();//create a map
test.put("1", "abc");//fill the values
test.put("2", "efg");//used map because values are stored in key -value pairs
test.put("3", "ghj");
for (String s : test.keySet()) {
// use the name as the key, and the icon as the value
editor.putString(s, nameIcons.get(s));//use the key as preference name
}
editor.commit();//commit the preferences
我有疑问,如果我错了,请纠正我,创建名为“abz”的 SharedPreference 文件,并在此文件中将首选项值存储为键值对,或者如果编辑器 obj 为每个键创建新的首选项文件,有什么用在创建共享首选项对象时提供首选项文件名?