0

I write dynamic preferences and I have an IllegalStateException with this code :

String key = "pref_key1";

CheckBoxPreference pref1 = new CheckBoxPreference(getActivity());
pref1.setKey(key);

Preference pref2 = new Preference(getActivity());
pref2.setKey("pref_key2");
pref2.setDependency(key);

The error is :

java.lang.IllegalStateException: Dependency "pref_key1" not found for preference "pref_key2"

Can you help me ? Thanks in advance

Yann
  • 41
  • 2
  • 1
    `setDependency()` will not work until both preferences are part of some "preference hierarchy". Having them both belong to the same `PreferenceScreen` may suffice. – CommonsWare Jan 18 '16 at 19:30
  • I add dependency after the two preferences have the same `PreferenceScreen` and it work prefectly. Thanks ! – Yann Jan 18 '16 at 19:47

0 Answers0