سؤال

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)

هل كانت مفيدة؟

المحلول

You can use

String value = listPreference.getValue();
int index = listPreference.findIndexOfValue(value);
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top