IT. Expert System.

Android Reference

PreferenceActivity


android.preference

Class PreferenceActivity

  • All Implemented Interfaces:
    ComponentCallbacks, ComponentCallbacks2, PreferenceFragment.OnPreferenceStartFragmentCallback, KeyEvent.Callback, LayoutInflater.Factory, LayoutInflater.Factory2, View.OnCreateContextMenuListener, Window.Callback
    Direct Known Subclasses:
    WallpaperSettingsActivity


    public abstract class PreferenceActivity
    extends ListActivity
    implements PreferenceFragment.OnPreferenceStartFragmentCallback
    This is the base class for an activity to show a hierarchy of preferences to the user. Prior to Build.VERSION_CODES.HONEYCOMB this class only allowed the display of a single set of preference; this functionality should now be found in the new PreferenceFragment class. If you are using PreferenceActivity in its old mode, the documentation there applies to the deprecated APIs here.

    This activity shows one or more headers of preferences, each of which is associated with a PreferenceFragment to display the preferences of that header. The actual layout and display of these associations can however vary; currently there are two major approaches it may take:

    • On a small screen it may display only the headers as a single list when first launched. Selecting one of the header items will re-launch the activity with it only showing the PreferenceFragment of that header.
    • On a large screen in may display both the headers and current PreferenceFragment together as panes. Selecting a header item switches to showing the correct PreferenceFragment for that item.

    Subclasses of PreferenceActivity should implement onBuildHeaders(java.util.List<android.preference.PreferenceActivity.Header>) to populate the header list with the desired items. Doing this implicitly switches the class into its new "headers + fragments" mode rather than the old style of just showing a single preferences list.

    Developer Guides

    For information about using PreferenceActivity, read the Settings guide.

    Sample Code

    The following sample code shows a simple preference activity that has two different sets of preferences. The implementation, consisting of the activity itself as well as its two preference fragments is:

    The preference_headers resource describes the headers to be displayed and the fragments associated with them. It is:

    The first header is shown by Prefs1Fragment, which populates itself from the following XML resource:

    Note that this XML resource contains a preference screen holding another fragment, the Prefs1FragmentInner implemented here. This allows the user to traverse down a hierarchy of preferences; pressing back will pop each fragment off the stack to return to the previous preferences.

    See PreferenceFragment for information on implementing the fragments themselves.

    • Field Detail

      • EXTRA_SHOW_FRAGMENT

        public static final String EXTRA_SHOW_FRAGMENT
        When starting this activity, the invoking Intent can contain this extra string to specify which fragment should be initially displayed.
        See Also:
        Constant Field Values
      • EXTRA_SHOW_FRAGMENT_ARGUMENTS

        public static final String EXTRA_SHOW_FRAGMENT_ARGUMENTS
        When starting this activity and using EXTRA_SHOW_FRAGMENT, this extra can also be specified to supply a Bundle of arguments to pass to that fragment when it is instantiated during the initial creation of PreferenceActivity.
        See Also:
        Constant Field Values
      • EXTRA_SHOW_FRAGMENT_TITLE

        public static final String EXTRA_SHOW_FRAGMENT_TITLE
        When starting this activity and using EXTRA_SHOW_FRAGMENT, this extra can also be specify to supply the title to be shown for that fragment.
        See Also:
        Constant Field Values
      • EXTRA_SHOW_FRAGMENT_SHORT_TITLE

        public static final String EXTRA_SHOW_FRAGMENT_SHORT_TITLE
        When starting this activity and using EXTRA_SHOW_FRAGMENT, this extra can also be specify to supply the short title to be shown for that fragment.
        See Also:
        Constant Field Values
      • EXTRA_NO_HEADERS

        public static final String EXTRA_NO_HEADERS
        When starting this activity, the invoking Intent can contain this extra boolean that the header list should not be displayed. This is most often used in conjunction with EXTRA_SHOW_FRAGMENT to launch the activity to display a specific fragment that the user has navigated to.
        See Also:
        Constant Field Values
      • HEADER_ID_UNDEFINED

        public static final long HEADER_ID_UNDEFINED
        Default value for Header.id indicating that no identifier value is set. All other values (including those below -1) are valid.
        See Also:
        Constant Field Values
    • Constructor Detail

      • PreferenceActivity

        public PreferenceActivity()
    • Method Detail

      • hasHeaders

        public boolean hasHeaders()
        Returns true if this activity is currently showing the header list.
      • isMultiPane

        public boolean isMultiPane()
        Returns true if this activity is showing multiple panes -- the headers and a preference fragment.
      • onIsMultiPane

        public boolean onIsMultiPane()
        Called to determine if the activity should run in multi-pane mode. The default implementation returns true if the screen is large enough.
      • onIsHidingHeaders

        public boolean onIsHidingHeaders()
        Called to determine whether the header list should be hidden. The default implementation returns the value given in EXTRA_NO_HEADERS or false if it is not supplied. This is set to false, for example, when the activity is being re-launched to show a particular preference activity.
      • onGetInitialHeader

        public PreferenceActivity.Header onGetInitialHeader()
        Called to determine the initial header to be shown. The default implementation simply returns the fragment of the first header. Note that the returned Header object does not actually need to exist in your header list -- whatever its fragment is will simply be used to show for the initial UI.
      • onBuildHeaders

        public void onBuildHeaders(List<PreferenceActivity.Header> target)
        Called when the activity needs its list of headers build. By implementing this and adding at least one item to the list, you will cause the activity to run in its modern fragment mode. Note that this function may not always be called; for example, if the activity has been asked to display a particular fragment without the header list, there is no need to build the headers.

        Typical implementations will use loadHeadersFromResource(int, java.util.List<android.preference.PreferenceActivity.Header>) to fill in the list from a resource.

        Parameters:
        target - The list in which to place the headers.
      • invalidateHeaders

        public void invalidateHeaders()
        Call when you need to change the headers being displayed. Will result in onBuildHeaders() later being called to retrieve the new list.
      • loadHeadersFromResource

        public void loadHeadersFromResource(int resid,
                                   List<PreferenceActivity.Header> target)
        Parse the given XML file as a header description, adding each parsed Header into the target list.
        Parameters:
        resid - The XML resource to load and parse.
        target - The list in which the parsed headers should be placed.
      • setListFooter

        public void setListFooter(View view)
        Set a footer that should be shown at the bottom of the header list.
      • onDestroy

        protected void onDestroy()
        Description copied from class: Activity
        Perform any final cleanup before an activity is destroyed. This can happen either because the activity is finishing (someone called Activity.finish() on it, or because the system is temporarily destroying this instance of the activity to save space. You can distinguish between these two scenarios with the Activity.isFinishing() method.

        Note: do not count on this method being called as a place for saving data! For example, if an activity is editing data in a content provider, those edits should be committed in either Activity.onPause() or Activity.onSaveInstanceState(android.os.Bundle), not here. This method is usually implemented to free resources like threads that are associated with an activity, so that a destroyed activity does not leave such things around while the rest of its application is still running. There are situations where the system will simply kill the activity's hosting process without calling this method (or any others) in it, so it should not be used to do things that are intended to remain around after the process goes away.

        Derived classes must call through to the super class's implementation of this method. If they do not, an exception will be thrown.

        Overrides:
        onDestroy in class ListActivity
        See Also:
        Activity.onDestroy()
      • onActivityResult

        protected void onActivityResult(int requestCode,
                            int resultCode,
                            Intent data)
        Description copied from class: Activity
        Called when an activity you launched exits, giving you the requestCode you started it with, the resultCode it returned, and any additional data from it. The resultCode will be Activity.RESULT_CANCELED if the activity explicitly returned that, didn't return any result, or crashed during its operation.

        You will receive this call immediately before onResume() when your activity is re-starting.

        Overrides:
        onActivityResult in class Activity
        Parameters:
        requestCode - The integer request code originally supplied to startActivityForResult(), allowing you to identify who this result came from.
        resultCode - The integer result code returned by the child activity through its setResult().
        data - An Intent, which can return result data to the caller (various data can be attached to Intent "extras").
        See Also:
        Activity.startActivityForResult(android.content.Intent, int), Activity.createPendingResult(int, android.content.Intent, int), Activity.setResult(int)
      • onListItemClick

        protected void onListItemClick(ListView l,
                           View v,
                           int position,
                           long id)
        Description copied from class: ListActivity
        This method will be called when an item in the list is selected. Subclasses should override. Subclasses can call getListView().getItemAtPosition(position) if they need to access the data associated with the selected item.
        Overrides:
        onListItemClick in class ListActivity
        Parameters:
        l - The ListView where the click happened
        v - The view that was clicked within the ListView
        position - The position of the view in the list
        id - The row id of the item that was clicked
      • onBuildStartFragmentIntent

        public Intent onBuildStartFragmentIntent(String fragmentName,
                                        Bundle args,
                                        int titleRes,
                                        int shortTitleRes)
        Called by startWithFragment(String, Bundle, Fragment, int, int, int) when in single-pane mode, to build an Intent to launch a new activity showing the selected fragment. The default implementation constructs an Intent that re-launches the current activity with the appropriate arguments to display the fragment.
        Parameters:
        fragmentName - The name of the fragment to display.
        args - Optional arguments to supply to the fragment.
        titleRes - Optional resource ID of title to show for this item.
        shortTitleRes - Optional resource ID of short title to show for this item.
        Returns:
        Returns an Intent that can be launched to display the given fragment.
      • startWithFragment

        public void startWithFragment(String fragmentName,
                             Bundle args,
                             Fragment resultTo,
                             int resultRequestCode,
                             int titleRes,
                             int shortTitleRes)
        Start a new instance of this activity, showing only the given preference fragment. When launched in this mode, the header list will be hidden and the given preference fragment will be instantiated and fill the entire activity.
        Parameters:
        fragmentName - The name of the fragment to display.
        args - Optional arguments to supply to the fragment.
        resultTo - Option fragment that should receive the result of the activity launch.
        resultRequestCode - If resultTo is non-null, this is the request code in which to report the result.
        titleRes - Resource ID of string to display for the title of this set of preferences.
        shortTitleRes - Resource ID of string to display for the short title of this set of preferences.
      • showBreadCrumbs

        public void showBreadCrumbs(CharSequence title,
                           CharSequence shortTitle)
        Change the base title of the bread crumbs for the current preferences. This will normally be called for you. See FragmentBreadCrumbs for more information.
      • setParentTitle

        public void setParentTitle(CharSequence title,
                          CharSequence shortTitle,
                          View.OnClickListener listener)
        Should be called after onCreate to ensure that the breadcrumbs, if any, were created. This prepends a title to the fragment breadcrumbs and attaches a listener to any clicks on the parent entry.
        Parameters:
        title - the title for the breadcrumb
        shortTitle - the short title for the breadcrumb
      • switchToHeader

        public void switchToHeader(String fragmentName,
                          Bundle args)
        When in two-pane mode, switch the fragment pane to show the given preference fragment.
        Parameters:
        fragmentName - The name of the fragment to display.
        args - Optional arguments to supply to the fragment.
      • switchToHeader

        public void switchToHeader(PreferenceActivity.Header header)
        When in two-pane mode, switch to the fragment pane to show the given preference fragment.
        Parameters:
        header - The new header to display.
      • startPreferenceFragment

        public void startPreferenceFragment(Fragment fragment,
                                   boolean push)
        Start a new fragment.
        Parameters:
        fragment - The fragment to start
        push - If true, the current fragment will be pushed onto the back stack. If false, the current fragment will be replaced.
      • startPreferencePanel

        public void startPreferencePanel(String fragmentClass,
                                Bundle args,
                                int titleRes,
                                CharSequence titleText,
                                Fragment resultTo,
                                int resultRequestCode)
        Start a new fragment containing a preference panel. If the prefences are being displayed in multi-pane mode, the given fragment class will be instantiated and placed in the appropriate pane. If running in single-pane mode, a new activity will be launched in which to show the fragment.
        Parameters:
        fragmentClass - Full name of the class implementing the fragment.
        args - Any desired arguments to supply to the fragment.
        titleRes - Optional resource identifier of the title of this fragment.
        titleText - Optional text of the title of this fragment.
        resultTo - Optional fragment that result data should be sent to. If non-null, resultTo.onActivityResult() will be called when this preference panel is done. The launched panel must use finishPreferencePanel(Fragment, int, Intent) when done.
        resultRequestCode - If resultTo is non-null, this is the caller's request code to be received with the resut.
      • finishPreferencePanel

        public void finishPreferencePanel(Fragment caller,
                                 int resultCode,
                                 Intent resultData)
        Called by a preference panel fragment to finish itself.
        Parameters:
        caller - The fragment that is asking to be finished.
        resultCode - Optional result code to send back to the original launching fragment.
        resultData - Optional result data to send back to the original launching fragment.
      • setPreferenceScreen

        @Deprecated
        public void setPreferenceScreen(PreferenceScreen preferenceScreen)
        Deprecated. This function is not relevant for a modern fragment-based PreferenceActivity.
        Sets the root of the preference hierarchy that this activity is showing.
        Parameters:
        preferenceScreen - The root PreferenceScreen of the preference hierarchy.
      • getPreferenceScreen

        @Deprecated
        public PreferenceScreen getPreferenceScreen()
        Deprecated. This function is not relevant for a modern fragment-based PreferenceActivity.
        Gets the root of the preference hierarchy that this activity is showing.
        Returns:
        The PreferenceScreen that is the root of the preference hierarchy.
      • addPreferencesFromIntent

        @Deprecated
        public void addPreferencesFromIntent(Intent intent)
        Deprecated. This function is not relevant for a modern fragment-based PreferenceActivity.
        Adds preferences from activities that match the given Intent.
        Parameters:
        intent - The Intent to query activities.
      • addPreferencesFromResource

        @Deprecated
        public void addPreferencesFromResource(int preferencesResId)
        Deprecated. This function is not relevant for a modern fragment-based PreferenceActivity.
        Inflates the given XML resource and adds the preference hierarchy to the current preference hierarchy.
        Parameters:
        preferencesResId - The XML resource ID to inflate.
      • onPreferenceTreeClick

        @Deprecated
        public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen,
                                               Preference preference)
        Deprecated. This function is not relevant for a modern fragment-based PreferenceActivity.
        Called when a preference in the tree rooted at this PreferenceScreen has been clicked.
        Parameters:
        preferenceScreen - The PreferenceScreen that the preference is located in.
        preference - The preference that was clicked.
        Returns:
        Whether the click was handled.
      • hasNextButton

        protected boolean hasNextButton()
      • getNextButton

        protected Button getNextButton()


Content

Android Reference

Java basics

Java Enterprise Edition (EE)

Java Standard Edition (SE)

SQL

HTML

PHP

CSS

Java Script

MYSQL

JQUERY

VBS

REGEX

C

C++

C#

Design patterns

RFC (standard status)

RFC (proposed standard status)

RFC (draft standard status)

RFC (informational status)

RFC (experimental status)

RFC (best current practice status)

RFC (historic status)

RFC (unknown status)

IT dictionary

License.
All information of this service is derived from the free sources and is provided solely in the form of quotations. This service provides information and interfaces solely for the familiarization (not ownership) and under the "as is" condition.
Copyright 2016 © ELTASK.COM. All rights reserved.
Site is optimized for mobile devices.
Downloads: 1102 / . Delta: 0.06106 с