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

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

问题描述

我以下面的方式创建了一个HashMap:

HashMap< Integer,String>按钮= new HashMap< Integer,String>();



我需要这种格式,但是这个解决方案的每个答案都是I只看过 HashMap< String,String>



谢谢



我只是改变了我不得不格式化的HashMap,然后执行以下操作以保存内容:

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

以及以下内容来检索HashpMap:

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


I have created a HashMap in the following way:

HashMap<Integer, String> buttons = new HashMap<Integer, String>();

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

Thanks

解决方案

Hey I found a way in the end :)

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();

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天全站免登陆