Storing Array List Object in SharedPreferences

前端 未结 3 1291
孤街浪徒
孤街浪徒 2020-12-02 10:04

This method add new object into ArrayList

//get text from textview
time = date.getText().toString();
entry_d = entry.getText().toString();
dayNa         


        
3条回答
  •  既然无缘
    2020-12-02 10:50

    Store Arraylist Using Shared Preferences

    SharedPreferences prefs=this.getSharedPreferences("yourPrefsKey",Context.MODE_PRIVATE);
    Editor edit=prefs.edit();
    
    Set set = new HashSet();
    set.addAll(your Arraylist Name);
    edit.putStringSet("yourKey", set);
    edit.commit();
    

    Retrieve Arraylist from Shared Preferences

    Set set = prefs.getStringSet("yourKey", null);
    List sample=new ArrayList(set);
    

提交回复
热议问题