IT. Expert System.

Android Reference

Preference


android.preference

Class Preference

    • Constructor Detail

      • Preference

        public Preference(Context context,
                  AttributeSet attrs,
                  int defStyle)
        Perform inflation from XML and apply a class-specific base style. This constructor of Preference allows subclasses to use their own base style when they are inflating. For example, a CheckBoxPreference constructor calls this version of the super class constructor and supplies android.R.attr.checkBoxPreferenceStyle for defStyle. This allows the theme's checkbox preference style to modify all of the base preference attributes as well as the CheckBoxPreference class's attributes.
        Parameters:
        context - The Context this is associated with, through which it can access the current theme, resources, SharedPreferences, etc.
        attrs - The attributes of the XML tag that is inflating the preference.
        defStyle - The default style to apply to this preference. If 0, no style will be applied (beyond what is included in the theme). This may either be an attribute resource, whose value will be retrieved from the current theme, or an explicit style resource.
        See Also:
        Preference(Context, AttributeSet)
      • Preference

        public Preference(Context context,
                  AttributeSet attrs)
        Constructor that is called when inflating a Preference from XML. This is called when a Preference is being constructed from an XML file, supplying attributes that were specified in the XML file. This version uses a default style of 0, so the only attribute values applied are those in the Context's Theme and the given AttributeSet.
        Parameters:
        context - The Context this is associated with, through which it can access the current theme, resources, SharedPreferences, etc.
        attrs - The attributes of the XML tag that is inflating the preference.
        See Also:
        Preference(Context, AttributeSet, int)
      • Preference

        public Preference(Context context)
        Constructor to create a Preference.
        Parameters:
        context - The Context in which to store Preference values.
    • Method Detail

      • onGetDefaultValue

        protected Object onGetDefaultValue(TypedArray a,
                               int index)
        Called when a Preference is being inflated and the default value attribute needs to be read. Since different Preference types have different value types, the subclass should get and return the default value which will be its value type.

        For example, if the value type is String, the body of the method would proxy to TypedArray.getString(int).

        Parameters:
        a - The set of attributes.
        index - The index of the default value attribute.
        Returns:
        The default value of this preference type.
      • setIntent

        public void setIntent(Intent intent)
        Sets an Intent to be used for Context.startActivity(Intent) when this Preference is clicked.
        Parameters:
        intent - The intent associated with this Preference.
      • setFragment

        public void setFragment(String fragment)
        Sets the class name of a fragment to be shown when this Preference is clicked.
        Parameters:
        fragment - The class name of the fragment associated with this Preference.
      • getFragment

        public String getFragment()
        Return the fragment class name associated with this Preference.
        Returns:
        The fragment class name last set via setFragment(java.lang.String) or XML.
      • getExtras

        public Bundle getExtras()
        Return the extras Bundle object associated with this preference, creating a new Bundle if there currently isn't one. You can use this to get and set individual extra key/value pairs.
      • peekExtras

        public Bundle peekExtras()
        Return the extras Bundle object associated with this preference, returning null if there is not currently one.
      • setLayoutResource

        public void setLayoutResource(int layoutResId)
        Sets the layout resource that is inflated as the View to be shown for this Preference. In most cases, the default layout is sufficient for custom Preference objects and only the widget layout needs to be changed.

        This layout should contain a ViewGroup with ID android.R.id#widget_frame to be the parent of the specific widget for this Preference. It should similarly contain android.R.id#title and android.R.id#summary.

        Parameters:
        layoutResId - The layout resource ID to be inflated and returned as a View.
        See Also:
        setWidgetLayoutResource(int)
      • getLayoutResource

        public int getLayoutResource()
        Gets the layout resource that will be shown as the View for this Preference.
        Returns:
        The layout resource ID.
      • setWidgetLayoutResource

        public void setWidgetLayoutResource(int widgetLayoutResId)
        Sets The layout for the controllable widget portion of this Preference. This is inflated into the main layout. For example, a CheckBoxPreference would specify a custom layout (consisting of just the CheckBox) here, instead of creating its own main layout.
        Parameters:
        widgetLayoutResId - The layout resource ID to be inflated into the main layout.
        See Also:
        setLayoutResource(int)
      • getWidgetLayoutResource

        public int getWidgetLayoutResource()
        Gets the layout resource for the controllable widget portion of this Preference.
        Returns:
        The layout resource ID.
      • getView

        public View getView(View convertView,
                   ViewGroup parent)
        Gets the View that will be shown in the PreferenceActivity.
        Parameters:
        convertView - The old View to reuse, if possible. Note: You should check that this View is non-null and of an appropriate type before using. If it is not possible to convert this View to display the correct data, this method can create a new View.
        parent - The parent that this View will eventually be attached to.
        Returns:
        Returns the same Preference object, for chaining multiple calls into a single statement.
        See Also:
        onCreateView(ViewGroup), onBindView(View)
      • onCreateView

        protected View onCreateView(ViewGroup parent)
        Creates the View to be shown for this Preference in the PreferenceActivity. The default behavior is to inflate the main layout of this Preference (see setLayoutResource(int). If changing this behavior, please specify a ViewGroup with ID android.R.id#widget_frame.

        Make sure to call through to the superclass's implementation.

        Parameters:
        parent - The parent that this View will eventually be attached to.
        Returns:
        The View that displays this Preference.
        See Also:
        onBindView(View)
      • onBindView

        protected void onBindView(View view)
        Binds the created View to the data for this Preference.

        This is a good place to grab references to custom Views in the layout and set properties on them.

        Make sure to call through to the superclass's implementation.

        Parameters:
        view - The View that shows this Preference.
        See Also:
        onCreateView(ViewGroup)
      • setOrder

        public void setOrder(int order)
        Sets the order of this Preference with respect to other Preference objects on the same level. If this is not specified, the default behavior is to sort alphabetically. The PreferenceGroup.setOrderingAsAdded(boolean) can be used to order Preference objects based on the order they appear in the XML.
        Parameters:
        order - The order for this Preference. A lower value will be shown first. Use DEFAULT_ORDER to sort alphabetically or allow ordering from XML.
        See Also:
        PreferenceGroup.setOrderingAsAdded(boolean), DEFAULT_ORDER
      • getOrder

        public int getOrder()
        Gets the order of this Preference with respect to other Preference objects on the same level.
        Returns:
        The order of this Preference.
        See Also:
        setOrder(int)
      • setTitle

        public void setTitle(CharSequence title)
        Sets the title for this Preference with a CharSequence. This title will be placed into the ID android.R.id#title within the View created by onCreateView(ViewGroup).
        Parameters:
        title - The title for this Preference.
      • setTitle

        public void setTitle(int titleResId)
        Sets the title for this Preference with a resource ID.
        Parameters:
        titleResId - The title as a resource ID.
        See Also:
        setTitle(CharSequence)
      • getTitleRes

        public int getTitleRes()
        Returns the title resource ID of this Preference. If the title did not come from a resource, 0 is returned.
        Returns:
        The title resource.
        See Also:
        setTitle(int)
      • setIcon

        public void setIcon(Drawable icon)
        Sets the icon for this Preference with a Drawable. This icon will be placed into the ID android.R.id#icon within the View created by onCreateView(ViewGroup).
        Parameters:
        icon - The optional icon for this Preference.
      • setIcon

        public void setIcon(int iconResId)
        Sets the icon for this Preference with a resource ID.
        Parameters:
        iconResId - The icon as a resource ID.
        See Also:
        setIcon(Drawable)
      • setSummary

        public void setSummary(CharSequence summary)
        Sets the summary for this Preference with a CharSequence.
        Parameters:
        summary - The summary for the preference.
      • setSummary

        public void setSummary(int summaryResId)
        Sets the summary for this Preference with a resource ID.
        Parameters:
        summaryResId - The summary as a resource.
        See Also:
        setSummary(CharSequence)
      • setEnabled

        public void setEnabled(boolean enabled)
        Sets whether this Preference is enabled. If disabled, it will not handle clicks.
        Parameters:
        enabled - Set true to enable it.
      • isEnabled

        public boolean isEnabled()
        Checks whether this Preference should be enabled in the list.
        Returns:
        True if this Preference is enabled, false otherwise.
      • setSelectable

        public void setSelectable(boolean selectable)
        Sets whether this Preference is selectable.
        Parameters:
        selectable - Set true to make it selectable.
      • isSelectable

        public boolean isSelectable()
        Checks whether this Preference should be selectable in the list.
        Returns:
        True if it is selectable, false otherwise.
      • setShouldDisableView

        public void setShouldDisableView(boolean shouldDisableView)
        Sets whether this Preference should disable its view when it gets disabled.

        For example, set this and setEnabled(boolean) to false for preferences that are only displaying information and 1) should not be clickable 2) should not have the view set to the disabled state.

        Parameters:
        shouldDisableView - Set true if this preference should disable its view when the preference is disabled.
      • getShouldDisableView

        public boolean getShouldDisableView()
        Checks whether this Preference should disable its view when it's action is disabled.
        Returns:
        True if it should disable the view.
        See Also:
        setShouldDisableView(boolean)
      • onClick

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

        public void setKey(String key)
        Sets the key for this Preference, which is used as a key to the SharedPreferences. This should be unique for the package.
        Parameters:
        key - The key for the preference.
      • getKey

        public String getKey()
        Gets the key for this Preference, which is also the key used for storing values into SharedPreferences.
        Returns:
        The key.
      • hasKey

        public boolean hasKey()
        Checks whether this Preference has a valid key.
        Returns:
        True if the key exists and is not a blank string, false otherwise.
      • isPersistent

        public boolean isPersistent()
        Checks whether this Preference is persistent. If it is, it stores its value(s) into the persistent SharedPreferences storage.
        Returns:
        True if it is persistent.
      • shouldPersist

        protected boolean shouldPersist()
        Checks whether, at the given time this method is called, this Preference should store/restore its value(s) into the SharedPreferences. This, at minimum, checks whether this Preference is persistent and it currently has a key. Before you save/restore from the SharedPreferences, check this first.
        Returns:
        True if it should persist the value.
      • setPersistent

        public void setPersistent(boolean persistent)
        Sets whether this Preference is persistent. When persistent, it stores its value(s) into the persistent SharedPreferences storage.
        Parameters:
        persistent - Set true if it should store its value(s) into the SharedPreferences.
      • callChangeListener

        protected boolean callChangeListener(Object newValue)
        Call this method after the user changes the preference, but before the internal state is set. This allows the client to ignore the user value.
        Parameters:
        newValue - The new value of this Preference.
        Returns:
        True if the user value should be set as the preference value (and persisted).
      • setOnPreferenceChangeListener

        public void setOnPreferenceChangeListener(Preference.OnPreferenceChangeListener onPreferenceChangeListener)
        Sets the callback to be invoked when this Preference is changed by the user (but before the internal state has been updated).
        Parameters:
        onPreferenceChangeListener - The callback to be invoked.
      • getOnPreferenceChangeListener

        public Preference.OnPreferenceChangeListener getOnPreferenceChangeListener()
        Returns the callback to be invoked when this Preference is changed by the user (but before the internal state has been updated).
        Returns:
        The callback to be invoked.
      • setOnPreferenceClickListener

        public void setOnPreferenceClickListener(Preference.OnPreferenceClickListener onPreferenceClickListener)
        Sets the callback to be invoked when this Preference is clicked.
        Parameters:
        onPreferenceClickListener - The callback to be invoked.
      • getOnPreferenceClickListener

        public Preference.OnPreferenceClickListener getOnPreferenceClickListener()
        Returns the callback to be invoked when this Preference is clicked.
        Returns:
        The callback to be invoked.
      • onKey

        public boolean onKey(View v,
                    int keyCode,
                    KeyEvent event)
        Allows a Preference to intercept key events without having focus. For example, SeekBarPreference uses this to intercept +/- to adjust the progress.
        Returns:
        True if the Preference handled the key. Returns false by default.
      • getContext

        public Context getContext()
        Returns the Context of this Preference. Each Preference in a Preference hierarchy can be from different Context (for example, if multiple activities provide preferences into a single PreferenceActivity). This Context will be used to save the Preference values.
        Returns:
        The Context of this Preference.
      • shouldCommit

        public boolean shouldCommit()
        Returns whether the Preference should commit its saved value(s) in getEditor(). This may return false in situations where batch committing is being done (by the manager) to improve performance.
        Returns:
        Whether the Preference should commit its saved value(s).
        See Also:
        getEditor()
      • compareTo

        public int compareTo(Preference another)
        Compares Preference objects based on order (if set), otherwise alphabetically on the titles.
        Specified by:
        compareTo in interface Comparable<Preference>
        Parameters:
        another - The Preference to compare to this one.
        Returns:
        0 if the same; less than 0 if this Preference sorts ahead of another; greater than 0 if this Preference sorts after another.
      • notifyChanged

        protected void notifyChanged()
        Should be called when the data of this Preference has changed.
      • notifyHierarchyChanged

        protected void notifyHierarchyChanged()
        Should be called when a Preference has been added/removed from this group, or the ordering should be re-evaluated.
      • onAttachedToHierarchy

        protected void onAttachedToHierarchy(PreferenceManager preferenceManager)
        Called when this Preference has been attached to a Preference hierarchy. Make sure to call the super implementation.
        Parameters:
        preferenceManager - The PreferenceManager of the hierarchy.
      • onAttachedToActivity

        protected void onAttachedToActivity()
        Called when the Preference hierarchy has been attached to the PreferenceActivity. This can also be called when this Preference has been attached to a group that was already attached to the PreferenceActivity.
      • findPreferenceInHierarchy

        protected Preference findPreferenceInHierarchy(String key)
        Finds a Preference in this hierarchy (the whole thing, even above/below your PreferenceScreen screen break) with the given key.

        This only functions after we have been attached to a hierarchy.

        Parameters:
        key - The key of the Preference to find.
        Returns:
        The Preference that uses the given key.
      • notifyDependencyChange

        public void notifyDependencyChange(boolean disableDependents)
        Notifies any listening dependents of a change that affects the dependency.
        Parameters:
        disableDependents - Whether this Preference should disable its dependents.
      • onDependencyChanged

        public void onDependencyChanged(Preference dependency,
                               boolean disableDependent)
        Called when the dependency changes.
        Parameters:
        dependency - The Preference that this Preference depends on.
        disableDependent - Set true to disable this Preference.
      • shouldDisableDependents

        public boolean shouldDisableDependents()
        Checks whether this preference's dependents should currently be disabled.
        Returns:
        True if the dependents should be disabled, otherwise false.
      • setDependency

        public void setDependency(String dependencyKey)
        Sets the key of a Preference that this Preference will depend on. If that Preference is not set or is off, this Preference will be disabled.
        Parameters:
        dependencyKey - The key of the Preference that this depends on.
      • getDependency

        public String getDependency()
        Returns the key of the dependency on this Preference.
        Returns:
        The key of the dependency.
        See Also:
        setDependency(String)
      • onPrepareForRemoval

        protected void onPrepareForRemoval()
        Called when this Preference is being removed from the hierarchy. You should remove any references to this Preference that you know about. Make sure to call through to the superclass implementation.
      • setDefaultValue

        public void setDefaultValue(Object defaultValue)
        Sets the default value for this Preference, which will be set either if persistence is off or persistence is on and the preference is not found in the persistent storage.
        Parameters:
        defaultValue - The default value.
      • onSetInitialValue

        protected void onSetInitialValue(boolean restorePersistedValue,
                             Object defaultValue)
        Implement this to set the initial value of the Preference.

        If restorePersistedValue is true, you should restore the Preference value from the SharedPreferences. If restorePersistedValue is false, you should set the Preference value to defaultValue that is given (and possibly store to SharedPreferences if shouldPersist() is true).

        This may not always be called. One example is if it should not persist but there is no default value given.

        Parameters:
        restorePersistedValue - True to restore the persisted value; false to use the given defaultValue.
        defaultValue - The default value for this Preference. Only use this if restorePersistedValue is false.
      • persistString

        protected boolean persistString(String value)
        Attempts to persist a String to the SharedPreferences.

        This will check if this Preference is persistent, get an editor from the PreferenceManager, put in the string, and check if we should commit (and commit if so).

        Parameters:
        value - The value to persist.
        Returns:
        True if the Preference is persistent. (This is not whether the value was persisted, since we may not necessarily commit if there will be a batch commit later.)
        See Also:
        getPersistedString(String)
      • getPersistedString

        protected String getPersistedString(String defaultReturnValue)
        Attempts to get a persisted String from the SharedPreferences.

        This will check if this Preference is persistent, get the SharedPreferences from the PreferenceManager, and get the value.

        Parameters:
        defaultReturnValue - The default value to return if either the Preference is not persistent or the Preference is not in the shared preferences.
        Returns:
        The value from the SharedPreferences or the default return value.
        See Also:
        persistString(String)
      • persistStringSet

        protected boolean persistStringSet(Set<String> values)
        Attempts to persist a set of Strings to the SharedPreferences.

        This will check if this Preference is persistent, get an editor from the PreferenceManager, put in the strings, and check if we should commit (and commit if so).

        Parameters:
        values - The values to persist.
        Returns:
        True if the Preference is persistent. (This is not whether the value was persisted, since we may not necessarily commit if there will be a batch commit later.)
        See Also:
        #getPersistedString(Set)
      • getPersistedStringSet

        protected Set<String> getPersistedStringSet(Set<String> defaultReturnValue)
        Attempts to get a persisted set of Strings from the SharedPreferences.

        This will check if this Preference is persistent, get the SharedPreferences from the PreferenceManager, and get the value.

        Parameters:
        defaultReturnValue - The default value to return if either the Preference is not persistent or the Preference is not in the shared preferences.
        Returns:
        The value from the SharedPreferences or the default return value.
        See Also:
        persistStringSet(Set)
      • persistInt

        protected boolean persistInt(int value)
        Attempts to persist an int to the SharedPreferences.
        Parameters:
        value - The value to persist.
        Returns:
        True if the Preference is persistent. (This is not whether the value was persisted, since we may not necessarily commit if there will be a batch commit later.)
        See Also:
        persistString(String), getPersistedInt(int)
      • getPersistedInt

        protected int getPersistedInt(int defaultReturnValue)
        Attempts to get a persisted int from the SharedPreferences.
        Parameters:
        defaultReturnValue - The default value to return if either this Preference is not persistent or this Preference is not in the SharedPreferences.
        Returns:
        The value from the SharedPreferences or the default return value.
        See Also:
        getPersistedString(String), persistInt(int)
      • persistFloat

        protected boolean persistFloat(float value)
        Attempts to persist a float to the SharedPreferences.
        Parameters:
        value - The value to persist.
        Returns:
        True if this Preference is persistent. (This is not whether the value was persisted, since we may not necessarily commit if there will be a batch commit later.)
        See Also:
        persistString(String), getPersistedFloat(float)
      • getPersistedFloat

        protected float getPersistedFloat(float defaultReturnValue)
        Attempts to get a persisted float from the SharedPreferences.
        Parameters:
        defaultReturnValue - The default value to return if either this Preference is not persistent or this Preference is not in the SharedPreferences.
        Returns:
        The value from the SharedPreferences or the default return value.
        See Also:
        getPersistedString(String), persistFloat(float)
      • persistLong

        protected boolean persistLong(long value)
        Attempts to persist a long to the SharedPreferences.
        Parameters:
        value - The value to persist.
        Returns:
        True if this Preference is persistent. (This is not whether the value was persisted, since we may not necessarily commit if there will be a batch commit later.)
        See Also:
        persistString(String), getPersistedLong(long)
      • getPersistedLong

        protected long getPersistedLong(long defaultReturnValue)
        Attempts to get a persisted long from the SharedPreferences.
        Parameters:
        defaultReturnValue - The default value to return if either this Preference is not persistent or this Preference is not in the SharedPreferences.
        Returns:
        The value from the SharedPreferences or the default return value.
        See Also:
        getPersistedString(String), persistLong(long)
      • persistBoolean

        protected boolean persistBoolean(boolean value)
        Attempts to persist a boolean to the SharedPreferences.
        Parameters:
        value - The value to persist.
        Returns:
        True if this Preference is persistent. (This is not whether the value was persisted, since we may not necessarily commit if there will be a batch commit later.)
        See Also:
        persistString(String), getPersistedBoolean(boolean)
      • getPersistedBoolean

        protected boolean getPersistedBoolean(boolean defaultReturnValue)
        Attempts to get a persisted boolean from the SharedPreferences.
        Parameters:
        defaultReturnValue - The default value to return if either this Preference is not persistent or this Preference is not in the SharedPreferences.
        Returns:
        The value from the SharedPreferences or the default return value.
        See Also:
        getPersistedString(String), persistBoolean(boolean)
      • toString

        public String toString()
        Description copied from class: Object
        Returns a string containing a concise, human-readable description of this object. Subclasses are encouraged to override this method and provide an implementation that takes into account the object's type and data. The default implementation is equivalent to the following expression:
           getClass().getName() + '@' + Integer.toHexString(hashCode())

        See Writing a useful toString method if you intend implementing your own toString method.

        Overrides:
        toString in class Object
        Returns:
        a printable representation of this object.
      • 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. This state should only contain information that is not persistent or can be reconstructed later.
        Returns:
        A Parcelable object containing the current dynamic state of this Preference, or null if there is nothing interesting to save. The default implementation returns null.
        See Also:
        onRestoreInstanceState(android.os.Parcelable), saveHierarchyState(android.os.Bundle)


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: 797 / . Delta: 0.12086 с