Build 1.0_r1(from source)

android.preference
Class PreferenceScreen

java.lang.Object
  extended by android.preference.Preference
      extended by android.preference.PreferenceGroup
          extended by android.preference.PreferenceScreen
All Implemented Interfaces:
DialogInterface.OnDismissListener, GenericInflater.Parent<Preference>, OnDependencyChangeListener, AdapterView.OnItemClickListener, Comparable<Preference>

public final class PreferenceScreen
extends PreferenceGroup
implements AdapterView.OnItemClickListener, DialogInterface.OnDismissListener

The PreferenceScreen class represents a top-level Preference that is the root of a Preference hierarchy. A PreferenceActivity points to an instance of this class to show the preferences. To instantiate this class, use PreferenceManager.createPreferenceScreen(Context).

This class can appear in two places:

  • When a PreferenceActivity points to this, it is used as the root and is not shown (only the contained preferences are shown).
  • When it appears inside another preference hierarchy, it is shown and serves as the gateway to another screen of preferences (either by showing another screen of preferences as a Dialog or via a Context.startActivity(android.content.Intent) from the Preference.getIntent()). The children of this PreferenceScreen are NOT shown in the screen that this PreferenceScreen is shown in. Instead, a separate screen will be shown when this preference is clicked.

    <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" android:key="first_preferencescreen"> <CheckBoxPreference android:key="wifi enabled" android:title="WiFi" /> <PreferenceScreen android:key="second_preferencescreen" android:title="WiFi settings"> <CheckBoxPreference android:key="prefer wifi" android:title="Prefer WiFi" /> ... other preferences here ... </PreferenceScreen> </PreferenceScreen> In this example, the "first_preferencescreen" will be used as the root of the hierarchy and given to a PreferenceActivity. The first screen will show preferences "WiFi" (which can be used to quickly enable/disable WiFi) and "WiFi settings". The "WiFi settings" is the "second_preferencescreen" and when clicked will show another screen of preferences such as "Prefer WiFi" (and the other preferences that are children of the "second_preferencescreen" tag).

    See Also:
    PreferenceCategory

    Nested Class Summary
     
    Nested classes/interfaces inherited from class android.preference.Preference
    Preference.BaseSavedState, Preference.OnPreferenceChangeInternalListener, Preference.OnPreferenceChangeListener, Preference.OnPreferenceClickListener
     
    Field Summary
     
    Fields inherited from class android.preference.Preference
    DEFAULT_ORDER
     
    Constructor Summary
    PreferenceScreen(Context context, AttributeSet attrs)
              Do NOT use this constructor, use PreferenceManager.createPreferenceScreen(Context).
     
    Method Summary
     void bind(ListView listView)
              Binds a ListView to the preferences contained in this PreferenceScreen via getRootAdapter().
     Dialog getDialog()
              Used to get a handle to the dialog.
     ListAdapter getRootAdapter()
              Returns an adapter that can be attached to a PreferenceActivity to show the preferences contained in this PreferenceScreen.
    protected  boolean isOnSameScreenAsChildren()
              Whether this preference group should be shown on the same screen as its contained preferences.
    protected  void onClick()
              Processes a click on the preference.
    protected  ListAdapter onCreateRootAdapter()
              Creates the root adapter.
     void onDismiss(DialogInterface dialog)
              This method will be invoked when the dialog is dismissed.
     void onItemClick(AdapterView parent, View view, int position, long id)
              Callback method to be invoked when an item in this AdapterView has been clicked.
    protected  void onRestoreInstanceState(Parcelable state)
              Hook allowing a preference to re-apply a representation of its internal state that had previously been generated by Preference.onSaveInstanceState().
    protected  Parcelable onSaveInstanceState()
              Hook allowing a preference to generate a representation of its internal state that can later be used to create a new instance with that same state.
     
    Methods inherited from class android.preference.PreferenceGroup
    addItemFromInflater, addPreference, dispatchRestoreInstanceState, dispatchSaveInstanceState, findPreference, getPreference, getPreferenceCount, isOrderingAsAdded, onAttachedToActivity, onPrepareAddPreference, onPrepareForRemoval, removeAll, removePreference, setEnabled, setOrderingAsAdded, sortPreferences
     
    Methods inherited from class android.preference.Preference
    callChangeListener, compareTo, findPreferenceInHierarchy, getContext, getDependency, getEditor, getFilterableStringBuilder, getId, getIntent, getKey, getLayoutResource, getOnPreferenceChangeListener, getOnPreferenceClickListener, getOrder, getPersistedBoolean, getPersistedFloat, getPersistedInt, getPersistedLong, getPersistedString, getPreferenceManager, getSharedPreferences, getShouldDisableView, getSummary, getTitle, getView, getWidgetLayoutResource, hasKey, hasSpecifiedLayout, isEnabled, isPersistent, isSelectable, notifyChanged, notifyDependencyChange, notifyHierarchyChanged, onAttachedToHierarchy, onBindView, onCreateView, onDependencyChanged, onGetDefaultValue, onSetInitialValue, performClick, persistBoolean, persistFloat, persistInt, persistLong, persistString, requireKey, restoreHierarchyState, saveHierarchyState, setDefaultValue, setDependency, setIntent, setKey, setLayoutResource, setOnPreferenceChangeInternalListener, setOnPreferenceChangeListener, setOnPreferenceClickListener, setOrder, setPersistent, setSelectable, setShouldDisableView, setSummary, setSummary, setTitle, setTitle, setWidgetLayoutResource, shouldCommit, shouldDisableDependents, shouldPersist, toString
     
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
     

    Constructor Detail

    PreferenceScreen

    public PreferenceScreen(Context context,
                            AttributeSet attrs)
    Do NOT use this constructor, use PreferenceManager.createPreferenceScreen(Context).

    Method Detail

    getRootAdapter

    public ListAdapter getRootAdapter()
    Returns an adapter that can be attached to a PreferenceActivity to show the preferences contained in this PreferenceScreen.

    This PreferenceScreen will NOT appear in the returned adapter, instead it appears in the hierarchy above this PreferenceScreen.

    This adapter's Adapter.getItem(int) should always return a subclass of Preference.

    Returns:
    An adapter that provides the Preference contained in this PreferenceScreen.
    See Also:
    PreferenceGroupAdapter

    onCreateRootAdapter

    protected ListAdapter onCreateRootAdapter()
    Creates the root adapter.

    Returns:
    An adapter that contains the preferences contained in this PreferenceScreen.
    See Also:
    getRootAdapter()

    bind

    public void bind(ListView listView)
    Binds a ListView to the preferences contained in this PreferenceScreen via getRootAdapter(). It also handles passing list item clicks to the corresponding Preference contained by this PreferenceScreen.

    Parameters:
    listView - The list view to attach to.

    onClick

    protected void onClick()
    Description copied from class: Preference
    Processes a click on the preference. This includes saving the value to the SharedPreferences. However, the overridden method should call Preference.callChangeListener(Object) to make sure the client wants to update the preference's state with the new value.

    Overrides:
    onClick in class Preference

    onDismiss

    public void onDismiss(DialogInterface dialog)
    Description copied from interface: DialogInterface.OnDismissListener
    This method will be invoked when the dialog is dismissed.

    Specified by:
    onDismiss in interface DialogInterface.OnDismissListener
    Parameters:
    dialog - The dialog that was dismissed will be passed into the method.

    getDialog

    public Dialog getDialog()
    Used to get a handle to the dialog. This is useful for cases where we want to manipulate the dialog as we would with any other activity or view.


    onItemClick

    public void onItemClick(AdapterView parent,
                            View view,
                            int position,
                            long id)
    Description copied from interface: AdapterView.OnItemClickListener
    Callback method to be invoked when an item in this AdapterView has been clicked.

    Implementers can call getItemAtPosition(position) if they need to access the data associated with the selected item.

    Specified by:
    onItemClick in interface AdapterView.OnItemClickListener
    Parameters:
    parent - The AdapterView where the click happened.
    view - The view within the AdapterView that was clicked (this will be a view provided by the adapter)
    position - The position of the view in the adapter.
    id - The row id of the item that was clicked.

    isOnSameScreenAsChildren

    protected boolean isOnSameScreenAsChildren()
    Description copied from class: PreferenceGroup
    Whether this preference group should be shown on the same screen as its contained preferences.

    Overrides:
    isOnSameScreenAsChildren in class PreferenceGroup
    Returns:
    True if the contained preferences should be shown on the same screen as this preference.

    onSaveInstanceState

    protected Parcelable onSaveInstanceState()
    Description copied from class: Preference
    Hook allowing a preference to generate a representation of its internal state that can later be used to create a new instance with that same state. This state should only contain information that is not persistent or can be reconstructed later.

    Overrides:
    onSaveInstanceState in class Preference
    Returns:
    Returns a Parcelable object containing the preference's current dynamic state, or null if there is nothing interesting to save. The default implementation returns null.
    See Also:
    Preference.onRestoreInstanceState(android.os.Parcelable), Preference.saveHierarchyState(android.os.Bundle), Preference.dispatchSaveInstanceState(android.os.Bundle)

    onRestoreInstanceState

    protected void onRestoreInstanceState(Parcelable state)
    Description copied from class: Preference
    Hook allowing a preference to re-apply a representation of its internal state that had previously been generated by Preference.onSaveInstanceState(). This function will never be called with a null icicle.

    Overrides:
    onRestoreInstanceState in class Preference
    Parameters:
    state - The frozen state that had previously been returned by Preference.onSaveInstanceState().
    See Also:
    Preference.onSaveInstanceState(), Preference.restoreHierarchyState(android.os.Bundle), Preference.dispatchRestoreInstanceState(android.os.Bundle)

    Build 1.0_r1(from source)

    Please submit a feedback, bug or feature