我有一个哈希映射表,如下所示,
HashMap<String, String> backUpCurency_values = new HashMap<String, String>();
我想存储这些值以供将来使用..我该怎么做?
Edit:
我将存储国家/地区名称和货币值作为键和值对...
您应该只使用 for-each 循环并像这样迭代地图:
SharedPreferences.Editor editor = getSharedPreferences(PREFS_NAME, 0).edit();
for( Entry<String, String> entry : backUpCurency_values.entrySet() )
editor.putString( entry.getKey(), entry.getValue() );
editor.commit();
然后,当您需要取回值以供以后使用时,您可以执行以下操作(前提是此 SharedPreference 对象是为货币保留的):
SharedPreferences prefs = getSharedPreferences(PREFS_NAME, 0);
for( Entry<String, ?> entry : prefs.getAll().entrySet() )
backUpCurency_values.put( entry.getKey(), entry.getValue().toString() );
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)