简体   繁体   中英

How to get current default item in ListPreference

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM