Some features of android.preference.ListPreference
The name or key of the Android:key option
Title of the Android:title option
Short summary of android:summary options
Android:entries the list item text to which the option can be set
Android:entryvalues define keys or values for each list item
Android:dialogtitle The title of the dialog box
Android:defaultvalue default values for options in item list
First step: Write Layout <?xml version= "1.0" encoding= "Utf-8"?>
<!--This file Is/res/xml/flightoptions.xml--
<preferencescreen
Xmlns:android= "Http://schemas.android.com/apk/res/android"
android:key= "Flight_option_preference"
android:title= "@string/preftile"
android:summary= "@string/prefsummary" >
<listpreference
android:key= "@string/ Selected_flight_sort_option " //Option name or key
android:title=" @ String/listtitle " //option title
android:summary=" @str Ing/listsummery " //short summary of options
android:entries=" @a Rray/flight_sort_options " //can set the option to a list item text
android:ent ryvalues= "@array/flight_sort_options_values" // define keys or values for each list item
android:dialogtitle= The title of the "@string/dialogtile" // dialog box
android:defaultvalue= The default value of the options in the "@string/flight_sort_option_default_value"/> //Item List
</preferencescreen>
Step Two: Load the layout
@Override
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Load the above layout flightoptions.xml
Addpreferencesfromresource (r.xml.flightoptions);
Preferencemanager Manager=getpreferencemanager ();
Listpreference listpreference= (listpreference) manager.findpreference ("Selected_flight_sort_option");
}
Step three: Write an array of list items
<?xml version= "1.0" encoding= "Utf-8"?>
<resources>
<string-array name= "Flight_sort_options" >
<item>total cost</item>
<item># of Stops</item>
<item>Airline</item>
</string-array>
<string-array name= "Flight_sort_options_values" >
<item>0</item>
<item>1</item>
<item>3</item>
</string-array>
</resources>
Fourth Step: Title
<?xml version= "1.0" encoding= "Utf-8"?>
<resources>
<string name= "App_name" >firstlistpreference demo</string>
<string name= "Menu_settings" >Settings</string>
<string name= "Hello_world" >hello world!</string>
<string name= "Preftile" >my preferences</string>
<string name= "prefsummary" >set flight option preferences</string>
<string name= "Selected_flight_sort_option" >selected_flight_sort_option</string>
<string name= "ListTitle" >flight option</string>
<string name= "listsummery" >set search options</string>
<string name= "Dialogtile" >choose Flight options</string>
<string name= "Flight_sort_option_default_value" >1</string>
</resources>
mtk-Settings-Select date format