문제

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