android spf中存list

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);            }        }    });}
相關文章
相關標籤/搜索