I have a ListPreference in the preference system for my Android application to allow the user to select one of five different accounts. Inside the preference, they should be able to switch between the accounts they want to use at the moment. The problem is that when I click on one of the options, I get a selection before the list has been opened. The code is as follows:
final ListPreference accountPref = (ListPreference) findPreference("accountPref");
CharSequence[] entries = { "Account 1", "Account 2", "Account 3", "Account 4", "Account 5" };
CharSequence[] entryValues = { "1", "2", "3", "4", "5" };
accountPref.setEntries(entries);
accountPref.setEntryValues(entryValues);
accountPref.setDefaultValue("1");
accountPref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
Log.i("theApp", "Selected = " + accountPref.getValue());
return true;
}
});
So, if I select the third entry in the dialog box, the log will return "1". If I then select the 5th, it will return β3β. It seems to be returning a choice before a new choice. How do I get the current selection, not the last?
Azhol source
share