我想迭代一個共享偏好的集合,並生成一個ArrayList的HashMaps,但有一個問題。從共享偏好Android數組
SharedPreferences settings = getSharedPreferences(pref, 0); SharedPreferences.Editor editor = settings.edit(); editor.putString("key1", "value1"); editor.putString("key2", "value2");
,然後我在想沿着線的東西:
final ArrayList<HashMap<String,String>> LIST = new ArrayList<HashMap<String,String>>(); SharedPreferences settings = getSharedPreferences(pref, 0); Map<String, ?> items = settings.getAll(); for(String s : items.keySet()){ HashMap<String,String> temp = new HashMap<String,String>(); temp.put("key", s); temp.put("value", items.get(s)); LIST.add(temp); }
這提供了以下錯誤:
The method put(String, String) in the type HashMap<String,String> is not applicable for the arguments (String, capture#5-of ?)
有沒有更好的方式來做到這一點?
無論API級別,檢查http://sherifandroid.blogspot.com/2012/05/string-arrays-and-object-arrays-in.html – 2012-06-14 10:02:44