如何存储 HashMap <Integer, String>在android中使用共享偏好? [英] How can I store a HashMap <Integer, String> in android using shared preferences?

查看:21
本文介绍了如何存储 HashMap <Integer, String>在android中使用共享偏好?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过以下方式创建了一个 HashMap:

I have created a HashMap in the following way:

HashMap<整数、字符串>按钮 = new HashMap<整数,字符串>();

我需要保持这种格式,但是我看到的这个解决方案的每个答案都只适用于 HashMap<String, String>

I need this to remain in this format, however every answer to this solution I have seen only works for HashMap<String, String>

谢谢

推荐答案

嘿嘿,我终于找到了办法:)

Hey I found a way in the end :)

我刚刚更改了必须格式化的 HashMap,然后执行以下操作来保存内容:

I just changed the HashMap I had to format and then did the following to save the contents:

SharedPreferences.Editor editor = getSharedPreferences(PREFS_NAME, 0).edit();
for( Entry entry : backUpCurency_values.entrySet() ) 
editor.putString( entry.getKey(), entry.getValue() );
editor.commit();

以及以下检索HashpMap:

and the following to retrieve the HashpMap:

SharedPreferences prefs = getSharedPreferences(PREFS_NAME, 0);
for( Entry entry : prefs.getAll().entrySet() )
   backUpCurency_values.put( entry.getKey(), entry.getValue().toString() );

这篇关于如何存储 HashMap &lt;Integer, String&gt;在android中使用共享偏好?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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