PreferenceScreen

public final class PreferenceScreen
extends PreferenceGroup

java.lang.Object
   ↳ androidx.preference.Preference
     ↳ androidx.preference.PreferenceGroup
       ↳ androidx.preference.PreferenceScreen


A top-level container that represents a settings screen. This is the root component of your Preference hierarchy. A PreferenceFragmentCompat points to an instance of this class to show the preferences. To instantiate this class, use PreferenceManager.createPreferenceScreen(Context).

Developer Guides

For information about building a settings screen using the AndroidX Preference library, see Settings.

Summary

Inherited constants

Public methods

void setShouldUseGeneratedIds(boolean shouldUseGeneratedIds)

Set whether the adapter created for this screen should attempt to use the preference IDs generated by PreferenceGroup.addPreference(Preference) as stable item IDs.

boolean shouldUseGeneratedIds()

See setShouldUseGeneratedIds(boolean)

Protected methods

boolean isOnSameScreenAsChildren()

Whether this preference group should be shown on the same screen as its contained preferences.

void onClick()

Processes a click on the preference.

Inherited methods

Public methods

setShouldUseGeneratedIds

public void setShouldUseGeneratedIds (boolean shouldUseGeneratedIds)

Set whether the adapter created for this screen should attempt to use the preference IDs generated by PreferenceGroup.addPreference(Preference) as stable item IDs. Setting this to false can suppress unwanted animations if Preference objects are frequently removed from and re-added to their containing PreferenceGroup.

This method may only be called when the preference screen is not attached to the hierarchy.

Default value is true.

Parameters
shouldUseGeneratedIds boolean: true if the adapter should use the preference ID as a stable ID, or false to disable the use of stable IDs.

shouldUseGeneratedIds

public boolean shouldUseGeneratedIds ()

See setShouldUseGeneratedIds(boolean)

Returns
boolean true if the adapter should use the preference IDs generated by PreferenceGroup.addPreference(Preference) as stable item IDs.

Protected methods

isOnSameScreenAsChildren

protected boolean isOnSameScreenAsChildren ()

Whether this preference group should be shown on the same screen as its contained preferences.

Returns
boolean true if the contained preferences should be shown on the same screen as this preference.

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.