PreferenceFragment.findPreference always returns NULL

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.


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.


You can solve this using

getFragmentManager().executePendingTransactions();

before

findPreference(section);