# Preference.SummaryProvider

# Preference.SummaryProvider

Artifact:[androidx.preference:preference](https://developer.android.com/jetpack/androidx/releases/preference)  
[View Source](https://cs.android.com/search?q=file:androidx/preference/Preference.java+class:androidx.preference.Preference.SummaryProvider)  
Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/preference#1.1.0)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/preference/Preference.SummaryProvider "View this page in Java")

<br />

```
interface Preference.SummaryProvider<T : Preference?>
```

<br />

Known direct subclasses  
[EditTextPreference.SimpleSummaryProvider](https://developer.android.com/reference/kotlin/androidx/preference/EditTextPreference.SimpleSummaryProvider),[ListPreference.SimpleSummaryProvider](https://developer.android.com/reference/kotlin/androidx/preference/ListPreference.SimpleSummaryProvider)  

|---------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [EditTextPreference.SimpleSummaryProvider](https://developer.android.com/reference/kotlin/androidx/preference/EditTextPreference.SimpleSummaryProvider) | A simple[androidx.preference.Preference.SummaryProvider](https://developer.android.com/reference/kotlin/androidx/preference/Preference.SummaryProvider)implementation for an[EditTextPreference](https://developer.android.com/reference/kotlin/androidx/preference/EditTextPreference). |
| [ListPreference.SimpleSummaryProvider](https://developer.android.com/reference/kotlin/androidx/preference/ListPreference.SimpleSummaryProvider)         | A simple[androidx.preference.Preference.SummaryProvider](https://developer.android.com/reference/kotlin/androidx/preference/Preference.SummaryProvider)implementation for a[ListPreference](https://developer.android.com/reference/kotlin/androidx/preference/ListPreference).          |

*** ** * ** ***

Interface definition for a callback to be invoked when the summary of this[Preference](https://developer.android.com/reference/kotlin/androidx/preference/Preference)is requested (typically when this preference is added to the hierarchy or its value is updated). Implement this to allow dynamically configuring a summary.

If a SummaryProvider is set,[setSummary](https://developer.android.com/reference/kotlin/androidx/preference/Preference#setSummary(java.lang.CharSequence))will throw an exception, and any existing value for the summary will not be used. The value returned by the SummaryProvider will be used instead whenever[getSummary](https://developer.android.com/reference/kotlin/androidx/preference/Preference#getSummary())is called on this preference.

Simple implementations are provided for[EditTextPreference](https://developer.android.com/reference/kotlin/androidx/preference/EditTextPreference)and[ListPreference](https://developer.android.com/reference/kotlin/androidx/preference/ListPreference). To enable these implementations, use[setSummaryProvider](https://developer.android.com/reference/kotlin/androidx/preference/Preference#setSummaryProvider(androidx.preference.Preference.SummaryProvider))with[getInstance](https://developer.android.com/reference/kotlin/androidx/preference/EditTextPreference.SimpleSummaryProvider#getInstance())or[getInstance](https://developer.android.com/reference/kotlin/androidx/preference/ListPreference.SimpleSummaryProvider#getInstance()).  

|                                               Parameters                                               |
|--------------------------------------------------------------------------------------------------------|------------------------------------------------------------|
| `<T : `[Preference](https://developer.android.com/reference/kotlin/androidx/preference/Preference)`?>` | The Preference class that a summary is being requested for |

## Summary

|                                       ### Public functions                                        |
|---------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [CharSequence](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-char-sequence/index.html)`?` | [provideSummary](https://developer.android.com/reference/kotlin/androidx/preference/Preference.SummaryProvider#provideSummary(T))`(preference: T)` Called whenever[getSummary](https://developer.android.com/reference/kotlin/androidx/preference/Preference#getSummary())is called on this preference. |

## Public functions

### provideSummary

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/preference#1.1.0)  

```
fun provideSummary(preference: T): CharSequence?
```

Called whenever[getSummary](https://developer.android.com/reference/kotlin/androidx/preference/Preference#getSummary())is called on this preference.  

|   Parameters    |
|-----------------|-----------------|
| `preference: T` | This preference |

|                                              Returns                                              |
|---------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------|
| [CharSequence](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-char-sequence/index.html)`?` | A CharSequence that will be displayed as the summary for this preference |