Hello I am writnig an Android app that has two preferences a checkbox and a preferencelist.
When the check box is marked as checked the preferencelist becomes enabled.
I have manage to save the checkbox "checked" status using putBoolean()
method.
getPreferenceManager().getSharedPreferences().edit().putBoolean(key, boolean);
getPreferenceManager().getSharedPreferences().edit().commit();
But how do I save the isEnabled
value so that when I leave and return it will not reset?
and how does putboolean knows to whice property to set the boolean anyway?
@Override
public void onPause() {
super.onPause();
save(l.isEnabled());
}
@Override
public void onResume() {
super.onResume();
l.setEnabled(load());
}
private void save(final boolean b) {
//what to put instead of key in order to save the preference list ENABLED sate??
getPreferenceManager().getSharedPreferences().edit().putBoolean(key, b);
getPreferenceManager().getSharedPreferences().edit().commit();
}
private boolean load(String key) {
return getPreferenceManager().getSharedPreferences().getBoolean(key, false);
}