You can use
String value = listPreference.getValue();
int index = listPreference.findIndexOfValue(value);
Frage
So I know how to get the currently selected item in a ListPreference
.
I also know how to set which item will be the default.
But I couldn't find the "reverse equivalent" of ListPreference.setDefaultValue()
.
Is there a way to determine, at runtime, which is the current default item
? (preferably its 0-based index in the ListPreference
)
Lösung
You can use
String value = listPreference.getValue();
int index = listPreference.findIndexOfValue(value);