PreferenceFragment.findPreference always returns NULL

夙愿已清 提交于 2019-11-29 03:57:40

Ok, i found what my problem was.

MultiSelectListPreference mslp = (MultiSelectListPreference) findPreference("contactList"); 

returns NULL because

addPreferencesFromResource(R.xml.preferences);

is not done at the start... so it didn't load my preferences in yet.

luismi

You can solve this using

getFragmentManager().executePendingTransactions();

before

findPreference(section);

In my case, I was trying to use findPreferences in onCreate of the enclosing PreferenceActivity. I moved it down to onCreate of the PreferenceFragment and it works fine.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!