简体   繁体   中英

Finding which preference is selected from ListPreference

I have a List Preference in the Preferences.xml folder. In my code I want to see which preference was selected from the List Preference, and use it in a particular condition. Is there any methods that will check for this? If not can anybody give me a pointer in the right direction.

Thanks Very Much,

XcutionX

You should be assigning the preference a key in your XML using android:key="pref_mykey" .

You then retrieve the value like so:

SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
String myPref = sharedPref.getString("pref_mykey", "default_value");

For more information I would suggest reading the Settings guide, specifically Reading Preferences .

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