Settings app Simple Learning record

Source: Internet
Author: User

Settings is the portal for Android system settings. The main interface is composed of Settings.java and Settings_headers.xml.

The settings class inherits from Preferenceactivity, and Preferenceactivity inherits from Listactivity,listactivity member variables that have listview and ListAdapter types.

1. How to build a page using preferenceactivity

Using Addpreferencesfromintent or Addpreferencesfromresource will define the contents of the headers (if loaded from resource, The file that is usually placed under the XML folder) is loaded into the preferenceactivity. Each defined header is a row of view in the ListView, of course, the displayed style will be different, such as the category title "Wireless and Network" and the following "WLAN" is actually a header.

Similar to the use of a ListView, we can use additional layout files to customize the UI for each row in the ListAdapter GetView method. For example, Wi-Fi and BT have switches, then use the layout of the Perference_header_switch_item.xml to build the view.

The internal properties of the system are used when constructing various page components, such as Holder.title = (TextView) View.findviewbyid (com.android.internal.r.id.title);

Each header corresponds to a fragment, which is specified in Settings_headers.xml using a label, such as android:fragment= "Com.android.settings.wifi.WifiSettings"

2, switching (switch) processing

To the WLAN switch example, in the settings will build Wifienabler instance, the instance switch to Wifienabler, the subsequent switch state maintenance, click event Monitoring all to Wifienabler to deal with.

3, set the value of the storage

in Settings's OnCreate function, the getsharedpreferences is present, so the set value is stored in the /data/data/com.android.settings/shared_prefs "under the Com.android.settings_preferences.xml.

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.