如何保存的ArrayList<&经纬度GT;使用共享preferences [英] How to save an arrayList<LatLng> with SharedPreferences

查看:225
本文介绍了如何保存的ArrayList<&经纬度GT;使用共享preferences的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找这一点 - 但发现只有如何保存的ArrayList比如这个code:

 编辑器prefsEditor = M prefs.edit();
 GSON GSON =新GSON();
 JSON字符串= gson.toJson(myObject的);
 prefsEditor.putString(MyObject来,JSON);
 prefsEditor.commit();

我要存储这个对象(点),这是在共享preferences的LatLng,在那之后我需要从这个拯救得到它。以下是我想要保存:

 公共无效onMapClick(经纬度点){
    // TODO自动生成方法存根    mMap.addMarker(。新的MarkerOptions()位置(点));
    ** checkPoints.add(点); **
}


解决方案

而不是使用preferences,你可以使用SQLite数据库。但是,如果你坚持使用共享preferences那么我不认为你有太多的选择,你只能存储布尔型,浮点型,整型,长字符串或StringSet。唯一可能的办法,我看到的是,您连接所有的值用自己喜欢分离

  1123.4456:1234.223 | 1123.4456:1234.1233 | 1123.4456:1234.223 | 1123.4456:1234.223

,然后检索时,它只是解析。

I was looking for this - but found only how to save an arrayList for example this code:

 Editor prefsEditor = mPrefs.edit();
 Gson gson = new Gson();
 String json = gson.toJson(MyObject);
 prefsEditor.putString("MyObject", json);
 prefsEditor.commit();

I want to store this object(point) which is LatLng in SharedPreferences, after that i will need to get it from this save. Here is what i want to save:

public void onMapClick(LatLng point) {
    // TODO Auto-generated method stub

    mMap.addMarker(new MarkerOptions().position(point));
    **checkPoints.add(point);**
}

解决方案

Instead of using preferences you can use Sqlite database. But if you insist on using SharedPreferences then I don't think you have much choice as you can only store boolean, float, int, long, String or StringSet. The only possible way I see is that you concatenate all of the values with your own separator like

1123.4456:1234.223|1123.4456:1234.1233|1123.4456:1234.223|1123.4456:1234.223

and then just parse when retrieving it.

这篇关于如何保存的ArrayList<&经纬度GT;使用共享preferences的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆