Last active
December 22, 2015 05:51
-
-
Save mr5z/9b4a81208e7da9431f7c to your computer and use it in GitHub Desktop.
Adding elements dynamically to MultiSelectListPreference
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
((EditTextPreference) findPreference("pref_scanning_editdialog")) | |
.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { | |
@Override | |
public boolean onPreferenceChange(Preference preference, Object newValue) { | |
String value = newValue.toString(); | |
if ( !value.isEmpty() ) { | |
// This doesn't seem right | |
CharSequence[] entries = list.getEntryValues(); | |
ArrayList<CharSequence> entryList = new ArrayList<>(Arrays.asList(entries)); | |
entryList.add(value); | |
CharSequence[] newEntries = entryList.toArray(new CharSequence[entryList.size()]); | |
list.setEntries(newEntries); | |
list.setEntryValues(newEntries); | |
} | |
return false; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment