我想在共享偏好设置中的不同事件上存储不同的值。
例如。我有一个切换按钮,将profilevisibility
设置为开启和关闭,因此,如果我选中切换按钮,它应将profilevisibility
值存储为1。
现在我还有另一个切换按钮,可以将matchPreference
设置为开启和关闭,所以如果我取消选中此切换按钮,则应将matchPreference
值设置为0。
会发生什么,当我将profileVisibility
设置为ON时,它会将值保存为1但是现在如果我将MatchPreference
设置为OFF,它也会保存值为0,但也会覆盖其他值。
这是我在活动
中调用OnCreate的代码HashMap<String, String> profileVisibility = session.getProfileVisibility();
profilevibility_value =profileVisibility.get(UserSessionManager.KEY_VISIBILITY);
HashMap<String, String> discoverability = session.getDiscoverablity();
discoverability_value = discoverability.get(UserSessionManager.KEY_DISCOVER);
HashMap<String, String> listmatches = session.getListMatches();
listmatches_value = listmatches.get(UserSessionManager.KEY_MATCH);
这里为所有三个变量覆盖的值,为什么?
这些是我在会话管理器中存储和获取值的方法
public static final String KEY_VISIBILITY = "1";
public static final String KEY_DISCOVER = "1";
public static final String KEY_MATCH = "1";
public void StoreProfileVisiblity(String male){
editor.putString(KEY_VISIBILITY, male);
editor.commit();
}
public void StoreDiscoverablity(String status){
editor.putString(KEY_DISCOVER, status);
editor.commit();
}
public void StoreListMatches(String match){
editor.putString(KEY_MATCH, match);
editor.commit();
}
public HashMap<String, String> getProfileVisibility(){
HashMap<String, String> mpv = new HashMap<String, String>();
mpv.put(KEY_VISIBILITY, pref.getString(KEY_VISIBILITY, null));
return mpv;
}
public HashMap<String, String> getDiscoverablity(){
HashMap<String, String> dv = new HashMap<String, String>();
dv.put(KEY_DISCOVER, pref.getString(KEY_DISCOVER, null));
return dv;
}
public HashMap<String, String> getListMatches(){
HashMap<String, String> lmv = new HashMap<String, String>();
lmv.put(KEY_MATCH, pref.getString(KEY_MATCH, null));
return lmv;
}