简体   繁体   English

如何在ListPreference中获取当前的默认项目

[英]How to get current default item in ListPreference

So I know how to get the currently selected item in a ListPreference . 所以我知道如何在ListPreference获取当前选择的项目

I also know how to set which item will be the default . 我也知道如何设置默认的项目

But I couldn't find the "reverse equivalent" of ListPreference.setDefaultValue() . 但是我找不到ListPreference.setDefaultValue()的“反向等效项”。

Is there a way to determine, at runtime, which is the current default item ? 有没有一种方法可以在运行时确定当前的默认item (preferably its 0-based index in the ListPreference ) (最好是ListPreference中从0开始的索引)

You can use 您可以使用

String value = listPreference.getValue();
int index = listPreference.findIndexOfValue(value);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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