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