mtk-Settings-Choose a date format

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.