android 使用SharedPreferences保存list数据
来源:互联网 发布:在淘宝联盟怎么推广 编辑:程序博客网 时间:2024/05/05 00:32
List<Map<String, String>> test = getInfo(this, "name");
for (int i = 0; i < test.size(); i++) {
Map<String, String> itemMap = test.get(i);
Iterator<Entry<String, String>> iterator = itemMap.entrySet()
.iterator();
while (iterator.hasNext()) {
Entry<String, String> entry = iterator.next();
if (!entry.getValue().equals(r.cashierNumber)) {
itemMap.put(entry.getKey(), entry.getValue());
}
}
itemMap.put(“test”, “test”);
list.add(itemMap);
saveInfo(this, "name", list);
}
public void saveInfo(Context context, String key,
List<Map<String, String>> datas) {
JSONArray mJsonArray = new JSONArray();
for (int i = 0; i < datas.size(); i++) {
Map<String, String> itemMap = datas.get(i);
Iterator<Entry<String, String>> iterator = itemMap.entrySet()
.iterator();
JSONObject object = new JSONObject();
while (iterator.hasNext()) {
Entry<String, String> entry = iterator.next();
try {
System.out.println(entry.getKey() + ":" + entry.getValue());
object.put(entry.getKey(), entry.getValue());
} catch (JSONException e) {
}
}
mJsonArray.put(object);
}
SharedPreferences sp = context.getSharedPreferences("listname",
Context.MODE_PRIVATE);
Editor editor = sp.edit();
editor.putString(key, mJsonArray.toString());
editor.commit();
}
public List<Map<String, String>> getInfo(Context context, String key) {
List<Map<String, String>> datas = new ArrayList<Map<String, String>>();
SharedPreferences sp = context.getSharedPreferences("listname",
Context.MODE_PRIVATE);
String result = sp.getString(key, "");
try {
JSONArray array = new JSONArray(result);
for (int i = 0; i < array.length(); i++) {
JSONObject itemObject = array.getJSONObject(i);
Map<String, String> itemMap = new HashMap<String, String>();
JSONArray names = itemObject.names();
if (names != null) {
for (int j = 0; j < names.length(); j++) {
String name = names.getString(j);
String value = itemObject.getString(name);
itemMap.put(name, value);
}
}
datas.add(itemMap);
}
} catch (JSONException e) {
}
return datas;
}
- android 使用SharedPreferences保存list数据
- android SharedPreferences保存list数据
- android利用SharedPreferences保存list集合数据
- Android 保存List数据(SharedPreferences)
- Android使用SharedPreferences保存数据实例
- Android --使用SharedPreferences保存和获取数据
- Android开发---使用SharedPreferences保存数据
- Android中使用SharedPreferences保存数据
- Android 使用SharedPreferences保存各种数据(List,Map,对象等)+ SpUtils工具
- Android 保存数据SharedPreferences
- SharedPreferences保存android数据
- android SharedPreferences保存数据
- 使用SharedPreferences保存数据
- android sharedpreferences 保存 list<Map<String,Object>>数据
- [Android]用SharedPreferences保存List<Map<String, String>>数据
- android SharedPreferences保存应用数据
- Android采用SharedPreferences保存数据
- Android采用SharedPreferences保存数据
- Linux环境Nginx安装多版本PHP
- 排序问题思考
- abstract class和interface的区别 及模板方法设计模式
- HDU 5387 Clock (MUT#8 模拟)
- 组播基础知识
- android 使用SharedPreferences保存list数据
- Android性能优化典范 - 第3季
- 对频率论(Frequentist)方法和贝叶斯方法(Bayesian Methods)的一个总结
- Android L——RecyclerView,CardView的导入和使用
- JToggleButton的重构状态以及ButtonGroup的使用
- 海水淡化膜:反渗透预处理对于海水淡化技术必要性
- 高斯滤波核计算 C版
- 【网络流】 HDOJ 5383 Yu-Gi-Oh!
- 最新kali linux 2.0 更新源(来自freebuf和网络)