Align "from code" parent-child preference flow with "from XML"

Add setDependency() call to make "from code" parent-child
behavior matched the "from XML" one.

Change-Id: I9e19a8bd16f69fb3101928831831103719a03a04
Signed-off-by: Joseph Judistira <joseph.judistira@gmail.com>
This commit is contained in:
Joseph Judistira
2012-10-12 16:10:25 -04:00
parent 84cf343170
commit 4ececa33b8

View File

@@ -32,17 +32,18 @@ import android.preference.SwitchPreference;
public class PreferencesFromCode extends PreferenceActivity {
private static final String PARENT_CHECKBOX_PREFERENCE = "parent_checkbox_preference";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setPreferenceScreen(createPreferenceHierarchy());
PreferenceScreen root = getPreferenceManager().createPreferenceScreen(this);
setPreferenceScreen(root);
populatePreferenceHierarchy(root);
}
private PreferenceScreen createPreferenceHierarchy() {
// Root
PreferenceScreen root = getPreferenceManager().createPreferenceScreen(this);
private void populatePreferenceHierarchy(PreferenceScreen root) {
// Inline preferences
PreferenceCategory inlinePrefCat = new PreferenceCategory(this);
inlinePrefCat.setTitle(R.string.inline_preferences);
@@ -132,6 +133,7 @@ public class PreferencesFromCode extends PreferenceActivity {
parentCheckBoxPref.setTitle(R.string.title_parent_preference);
parentCheckBoxPref.setSummary(R.string.summary_parent_preference);
prefAttrsCat.addPreference(parentCheckBoxPref);
parentCheckBoxPref.setKey(PARENT_CHECKBOX_PREFERENCE);
// Visual child toggle preference
// See res/values/attrs.xml for the <declare-styleable> that defines
@@ -144,8 +146,7 @@ public class PreferencesFromCode extends PreferenceActivity {
a.getResourceId(R.styleable.TogglePrefAttrs_android_preferenceLayoutChild,
0));
prefAttrsCat.addPreference(childCheckBoxPref);
childCheckBoxPref.setDependency(PARENT_CHECKBOX_PREFERENCE);
a.recycle();
return root;
}
}