belongs to Maven artifact com.android.support:preference-v7:28.0.0-alpha1
Preference
public
class
Preference
extends Object
implements
Comparable<Preference>
java.lang.Object | |
↳ | android.support.v7.preference.Preference |
![]() |
![]() |
Represents the basic Preference UI building
block displayed by a PreferenceFragmentCompat
in the form of a
RecyclerView
. This class provides data for the
View
to be displayed
in the list and associates with a SharedPreferences
to
store/retrieve the preference data.
When specifying a preference hierarchy in XML, each element can point to a
subclass of Preference
, similar to the view hierarchy and layouts.
This class contains a key
that will be used as the key into the
SharedPreferences
. It is up to the subclass to decide how to store
the value.
Developer Guides
For information about building a settings UI with Preferences, read the Settings guide.
Summary
Nested classes | |
---|---|
class |
Preference.BaseSavedState
A base class for managing the instance state of a |
interface |
Preference.OnPreferenceChangeListener
Interface definition for a callback to be invoked when the value of this
|
interface |
Preference.OnPreferenceClickListener
Interface definition for a callback to be invoked when a |
XML attributes | |
---|---|
Preference_android_iconSpaceReserved |
|
Preference_android_singleLineTitle |
Constants | |
---|---|
int |
DEFAULT_ORDER
Specify for |
Public constructors | |
---|---|
Preference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)
Perform inflation from XML and apply a class-specific base style. |
|
Preference(Context context, AttributeSet attrs, int defStyleAttr)
Perform inflation from XML and apply a class-specific base style. |
|
Preference(Context context, AttributeSet attrs)
Constructor that is called when inflating a Preference from XML. |
|
Preference(Context context)
Constructor to create a Preference. |
Public methods | |
---|---|
boolean
|
callChangeListener(Object newValue)
Call this method after the user changes the preference, but before the internal state is set. |
int
|
compareTo(Preference another)
Compares Preference objects based on order (if set), otherwise alphabetically on the titles. |
Context
|
getContext()
Returns the |
String
|
getDependency()
Returns the key of the dependency on this Preference. |
Bundle
|
getExtras()
Return the extras Bundle object associated with this preference, creating a new Bundle if there currently isn't one. |
String
|
getFragment()
Return the fragment class name associated with this Preference. |
Drawable
|
getIcon()
Returns the icon of this Preference. |
Intent
|
getIntent()
Return the |
String
|
getKey()
Gets the key for this Preference, which is also the key used for storing values into
|
final
int
|
getLayoutResource()
Gets the layout resource that will be shown as the |
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). |
Preference.OnPreferenceClickListener
|
getOnPreferenceClickListener()
Returns the callback to be invoked when this Preference is clicked. |
int
|
getOrder()
Gets the order of this Preference with respect to other Preference objects on the same level. |
PreferenceGroup
|
getParent()
Returns the |
Set<String>
|
getPersistedStringSet(Set<String> defaultReturnValue)
Attempts to get a persisted set of Strings if this Preference is persistent. |
PreferenceDataStore
|
getPreferenceDataStore()
Returns |
PreferenceManager
|
getPreferenceManager()
Gets the |
SharedPreferences
|
getSharedPreferences()
Returns the |
boolean
|
getShouldDisableView()
Checks whether this Preference should disable its view when it's action is disabled. |
CharSequence
|
getSummary()
Returns the summary of this Preference. |
CharSequence
|
getTitle()
Returns the title of this Preference. |
final
int
|
getWidgetLayoutResource()
Gets the layout resource for the controllable widget portion of this Preference. |
boolean
|
hasKey()
Checks whether this Preference has a valid key. |
boolean
|
isEnabled()
Checks whether this Preference should be enabled in the list. |
boolean
|
isIconSpaceReserved()
Returns whether the space of this preference icon view is reserved. |
boolean
|
isPersistent()
Checks whether this Preference is persistent. |
boolean
|
isSelectable()
Checks whether this Preference should be selectable in the list. |
boolean
|
isSingleLineTitle()
Gets whether the title of this preference is constrained to a single line. |
final
boolean
|
isVisible()
Checks whether this preference should be visible to the user in the list. |
void
|
notifyDependencyChange(boolean disableDependents)
Notifies any listening dependents of a change that affects the dependency. |
void
|
onAttached()
Called when the Preference hierarchy has been attached to the list of preferences. |
void
|
onBindViewHolder(PreferenceViewHolder holder)
Binds the created View to the data for this Preference. |
void
|
onDependencyChanged(Preference dependency, boolean disableDependent)
Called when the dependency changes. |
void
|
onDetached()
Called when the Preference hierarchy has been detached from the list of preferences. |
void
|
onInitializeAccessibilityNodeInfo(AccessibilityNodeInfoCompat info)
Initializes an |
void
|
onParentChanged(Preference parent, boolean disableChild)
Called when the implicit parent dependency changes. |
Bundle
|
peekExtras()
Return the extras Bundle object associated with this preference, returning null if there is not currently one. |
boolean
|
persistStringSet(Set<String> values)
Attempts to persist a set of Strings if this Preference is persistent. |
void
|
|