当我不知道密钥时,如何从 sharedpreference 中获取值?
这是我保存到共享首选项的代码:
String materia = data.getExtras().getString("materia");
String profesor = data.getExtras().getString("profesor");
String color = data.getExtras().getString("color");
SharedPreferences saveMateria = getSharedPreferences(
tabChangedto, MODE_PRIVATE);
SharedPreferences.Editor editor = saveMateria.edit();
editor.putString(materia, materia);
editor.putString(profesor, profesor);
editor.putString("color", color);
editor.commit();
我试过这个:
ArrayList<MateriaComplex> array = new ArrayList<MateriaComplex>();
pref = getSharedPreferences(tabChangedto, MODE_PRIVATE);
Map<String, ?> keys = pref.getAll();
for (Map.Entry<String, ?> entry : keys.entrySet()) {
/*
*
* Here i want to extract the color value,materia value, profesor value.
* But i don't know how, because the key has the name of the value, to avoid replacing it.
*
*/
}