简体   繁体   English

如何在共享首选项Android中添加多个值

[英]how to add multiple values in shared preferences android

I have shared preference . 我有共同的偏好。 I want to store multiple values that are present on the listview . 我想存储listview上存在的多个值。

I am getting the data but not full data . 我正在获取数据,但没有完整的数据。

The code is present in the base adapter and kindly please help me i am running out of time . 该代码存在于基本适配器中,请帮我,我用光了时间。

Map<String, String> nameIcons = new HashMap<String, String>();
    nameIcons.put("publisheddate",publisheddate);
    nameIcons.put("validity",validity);
    nameIcons.put("accessstatus",accessstatus);

      settings=ctxt.getSharedPreferences("com.contentraven",0);
      editor=settings.edit();

      editor.clear();
      editor.commit();
      for (String s : nameIcons.keySet()) 
      {
          editor.putString(s, nameIcons.get(s));
      }

      editor.commit();

Try this code .. 试试这个代码..

//For storing
      Map<String, String> nameIcons = new HashMap<String, String>();
      nameIcons.put("publisheddate",publisheddate);
      nameIcons.put("validity",validity);
      nameIcons.put("accessstatus",accessstatus);
      SharedPreferences pref = getContext().getSharedPreferences("com.contentraven",0);
      SharedPreferences.Editor editor = pref.edit(); 
      editor.clear();
      editor.commit();

      for (String s : nameIcons.keySet()) {
         editor.putString(s, map.get(s));
      }
      editor.commit();          

// for loading            
       SharedPreferences pref =   getContext().getSharedPreferences("com.contentraven",0);
       HashMap<String, String> map= (HashMap<String, String>) pref.getAll();
       int i=0;
       String val[]=new String[map.size()]; 
       for (String s : map.keySet()) {
            val[i]=map.get(s);

           i++;
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM