存List数据
SharedPreferences sp2 = getActivity().getSharedPreferences("ABC", Activity.MODE_PRIVATE);
Gson gson = new Gson();
String data = gson.toJson(list);
SharedPreferences.Editor editor = sp2.edit();
editor.putString("list", data).commit();
取List数据
SharedPreferences sp = getSharedPreferences("ABC", Activity.MODE_PRIVATE);
List<Info> listJson = sp.getString("list", "");
Gson gson = new Gson();
quickGroupList = gson.fromJson(listJson, new TypeToken<List<Info>>() {}.getType()); //将json字符串转换成List集合
Android中向SharedPreferences存取List数据
猜你喜欢
转载自blog.csdn.net/aidou1314/article/details/95953740
今日推荐
周排行