参见英文答案 > Save ArrayList to SharedPreferences 31个
我在SharedPreferences中保存ArrayList大小和数据.当我从SharedPreference中检索ArrayList大小时,它会提供与之前保存的大小无关的确切大小.但是在这里我没有保存ArrayList数据.当我检索ArrayList数据时,它总是给出ArrayList的最后一项.
这是我保存ArrayList大小和数据的代码:
@H_404_9@ArrayList
在这里,我正在检索我的ArrayList项:
@H_404_9@ String getListSize = MyPreferences.savePreferences(getActivity(),"arraylist_size"); System.out.println("arrayList size : " + getListSize); if (!getListSize.equals("")) { int listSize = Integer.parseInt(getListSize); if (listSize > 0) { for (int i = 0; i < listSize; i++) { String getListitems = MyPreferences .getPreferences(getActivity(),"id"); System.out.Println("list items : "+ getListItems); } } }
如何在SharedPreferences中存储ArrayList项?
最佳答案
试试这个:
原文链接:https://www.f2er.com/android/431023.html@H_404_9@//Set the values SetscoreEditor.putStringSet("key",set); scoreEditor.commit(); //Retrieve the values Set scores.getStringSet("key",null);
这个问题已经在这里回答了Save ArrayList to SharedPreferences
@H_404_9@public void addTask(Task t) { if (null == currentTasks) { currentTasks = new ArrayList
@H_404_9@public void onCreate() { super.onCreate(); if (null == currentTasks) { currentTasks = new ArrayList
在这里,您将任务类更改为itemclass.