How to save dynamically added items in Listview with sharedpreferences?

前端 未结 3 1162
青春惊慌失措
青春惊慌失措 2021-01-27 08:14
        protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.a         


        
3条回答
  •  花落未央
    2021-01-27 08:31

    You can store string sets in Shared Preferences, then convert them back to a List when you retrieve them.

    ArrayList list = new ArrayList();
    list.add("test1");
    list.add("test2");
    
    PreferenceManager.getDefaultSharedPreferences(context)
        .edit()
        .putStringSet("stringset", new HashSet(list))
        .commit();
    

提交回复
热议问题