private void setSpfList() {
final SharedPreferences mSharedPreferences = getPreferences(Context.MODE_PRIVATE);
// Get SharedPreferences editor
final SharedPreferences.Editor mEditor = mSharedPreferences.edit();
findViewById(R.id.save).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//储存
ArrayList<String> list = new ArrayList<String>();
list.add("1111");
list.add("2222");
list.add("3333");
list.add("4444");
Set set = new HashSet();
set.addAll(list);
mEditor.putStringSet("aaa", set);
mEditor.commit();
}
});
//得到
findViewById(R.id.get).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Set<String> set = mSharedPreferences.getStringSet("aaa", null);
for (String s : set) {
Log.i("数据",s);
}
}
});
}