Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CheckBoxPreference dependency not found error

I have this CheckBoxPreference

CheckBoxPreference sendToEmailPref = new CheckBoxPreference(this);
sendToEmailPref.setTitle("Send To Email");
sendToEmailPref.setDependency("emailList");

I want to set its dependency on a key "emailList" emailList is a custom build preference which stores the email addressees as a String.

However, I am getting this error

Caused by: java.lang.IllegalStateException: Dependency not found.....
like image 612
humansg Avatar asked Dec 06 '22 16:12

humansg


2 Answers

you should call setDependency after you have finished calling addPreference It works for me well!

like image 197
summer Avatar answered Dec 21 '22 15:12

summer


Get your .setDependency() to just after setPreferenceScreen() in your onCreate. It should work.

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setPreferenceScreen(createPreferenceHierarchy());
    getPreferenceScreen().findPreference("_key_of_depend_to_").setDependency("emailList");
}
like image 29
ys126 Avatar answered Dec 21 '22 17:12

ys126