I am trying to change the entryvalue of a listpreference depending on wether a checkbox is ticked or not…
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);{
if(sharedPrefs.getBoolean("french", false))
{
Preference newsPref = (Preference) findPreference("news_feed");
newsPref.setDefaultValue("@array/newsfeedfr");
}
else
{
Preference newsPref = (Preference) findPreference("news_feed");
newsPref.setEntryValues("@array/newsfeed");
}
}
i get errors on the .setEntryValue with this:
The method setEntryValues(String) is undefined for the type Preference
One issue that you have is in how you’re referencing your array values.
@array/newsfeedis used in XML files, not Java!You probably want to use
getResources().getStringArray(R.array.newsfeed)or similar. Source.Another issue is that
setEntryValues()isn’t defined forPreferences, you need to initialise as aListPreferenceinstead.