如何在android中使用putStringSet在共享首选项中存储多维数组?

时间:2014-04-23 10:35:32

标签: android multidimensional-array sharedpreferences

当我尝试使用shared preference

putStringSet中保存数据时,此代码出错 请告诉我,我做错了。

我这样做:

 public void onReceive(Context arg0, Intent arg1) {
String[][] my_date;
    my_date = new String[][] {
            {"14","26"},
            {"12","16","24","27"},
            {"17"},
            {"8","13","18"},
            {"14"},
            {},
            {"29"},
            {"15","18"},
            {},
            {"2","3","6","8","23"},
            {"4","6","24"},
            {}
    };
   SharedPreferences pref = arg0.getSharedPreferences("MyPref", 0); // 0 - for private mode
    SharedPreferences.Editor editor = pref.edit();
    Set<String> myStrings = pref.**getStringSet**("my_date", new HashSet<String>());
                myStrings.add("Another string");
           editor.putStringSet("myStrings", myStrings);
           editor.commit();
}

0 个答案:

没有答案