Preferencefragment.findpreference Always Returns Null
I'm currently trying to make a settings menu, that will show a MultiSelectListPreference, to select multiple contacts from your contact list. At this moment, I'm receiving an NullP
Solution 1:
Ok, i found what my problem was.
MultiSelectListPreferencemslp= (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.
Solution 2:
You can solve this using
getFragmentManager().executePendingTransactions();
before
findPreference(section);
Solution 3:
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.
Solution 4:
You can solve this by placing the all the content access functions inside the following fragment callback
@OverridepublicvoidonActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
//Access the content here.
}
Post a Comment for "Preferencefragment.findpreference Always Returns Null"