# ClickableSpan

# ClickableSpan

Artifact:[androidx.car.app:app](https://developer.android.com/jetpack/androidx/releases/car-app)  
[View Source](https://cs.android.com/search?q=file:androidx/car/app/model/ClickableSpan.java+class:androidx.car.app.model.ClickableSpan)  
Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.0.0)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/car/app/model/ClickableSpan "View this page in Java")

<br />

```
@RequiresCarApi(value = 2)
@CarProtocol
class ClickableSpan : CarSpan
```

<br />

|---|---|---|-----------------------------------------------------------------------------------------------------------------------------|
| [kotlin.Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html)                                                   ||||
| ↳ | [android.text.style.CharacterStyle](https://developer.android.com/reference/android/text/style/CharacterStyle.html)               |||
|   | ↳ | [androidx.car.app.model.CarSpan](https://developer.android.com/reference/kotlin/androidx/car/app/model/CarSpan)                ||
|   |   | ↳ | [androidx.car.app.model.ClickableSpan](https://developer.android.com/reference/kotlin/androidx/car/app/model/ClickableSpan) |

*** ** * ** ***

A span that makes a section of text clickable.

The text of this span will be highlighted by the host, so users understand that it is interactive. If this span overlaps the other spans (for example,[ForegroundCarColorSpan](https://developer.android.com/reference/kotlin/androidx/car/app/model/ForegroundCarColorSpan)), the host might choose to ignore those spans if they conflict on how clickable text is highlighted.

The host may ignore[ClickableSpan](https://developer.android.com/reference/kotlin/androidx/car/app/model/ClickableSpan)s unless support for it is explicitly documented in the API that takes the string.

For example, to make a portion of a text clickable:  

```kotlin
SpannableString string = new SpannableString("Text with a clickable span");
string.setSpan(ClickableSpan.create(
    new OnClickListener
    ), 12, 22, Spanned.SPAN_INCLUSIVE_EXCLUSIVE));
```

## Summary

|                                                ### Public functions                                                |
|--------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `java-static `[ClickableSpan](https://developer.android.com/reference/kotlin/androidx/car/app/model/ClickableSpan) | [create](https://developer.android.com/reference/kotlin/androidx/car/app/model/ClickableSpan#create(androidx.car.app.model.OnClickListener))`(onClickListener: `[OnClickListener](https://developer.android.com/reference/kotlin/androidx/car/app/model/OnClickListener)`)` Creates a[ClickableSpan](https://developer.android.com/reference/kotlin/androidx/car/app/model/ClickableSpan)from a[OnClickListener](https://developer.android.com/reference/kotlin/androidx/car/app/model/OnClickListener). |
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)                                | [equals](https://developer.android.com/reference/kotlin/androidx/car/app/model/ClickableSpan#equals(java.lang.Object))`(other: `[Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html)`?)`                                                                                                                                                                                                                                                                                          |
| [OnClickDelegate](https://developer.android.com/reference/kotlin/androidx/car/app/model/OnClickDelegate)           | [getOnClickDelegate](https://developer.android.com/reference/kotlin/androidx/car/app/model/ClickableSpan#getOnClickDelegate())`()` Returns the[OnClickDelegate](https://developer.android.com/reference/kotlin/androidx/car/app/model/OnClickDelegate)associated with this span.                                                                                                                                                                                                                         |
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                                        | [hashCode](https://developer.android.com/reference/kotlin/androidx/car/app/model/ClickableSpan#hashCode())`()`                                                                                                                                                                                                                                                                                                                                                                                           |
| [String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)                                  | [toString](https://developer.android.com/reference/kotlin/androidx/car/app/model/ClickableSpan#toString())`()`                                                                                                                                                                                                                                                                                                                                                                                           |

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     ### Inherited functions                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| From[androidx.car.app.model.CarSpan](https://developer.android.com/reference/kotlin/androidx/car/app/model/CarSpan) |-------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | [updateDrawState](https://developer.android.com/reference/kotlin/androidx/car/app/model/CarSpan#updateDrawState(android.text.TextPaint))`(tp: `[TextPaint](https://developer.android.com/reference/android/text/TextPaint.html)`)` |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| From[android.text.style.CharacterStyle](https://developer.android.com/reference/android/text/style/CharacterStyle.html) |-------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | [CharacterStyle](https://developer.android.com/reference/android/text/style/CharacterStyle.html)`!`               | [getUnderlying](https://developer.android.com/reference/android/text/style/CharacterStyle.html#getUnderlying())`()`                                                                                                                       | | `abstract `[Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                          | [updateDrawState](https://developer.android.com/reference/android/text/style/CharacterStyle.html#updateDrawState(android.text.TextPaint))`(p: `[TextPaint](https://developer.android.com/reference/android/text/TextPaint.html)`!)`       | | `java-static `[CharacterStyle](https://developer.android.com/reference/android/text/style/CharacterStyle.html)`!` | [wrap](https://developer.android.com/reference/android/text/style/CharacterStyle.html#wrap(android.text.style.CharacterStyle))`(cs: `[CharacterStyle](https://developer.android.com/reference/android/text/style/CharacterStyle.html)`!)` | |

## Public functions

### create

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.0.0)  

```
java-static fun create(onClickListener: OnClickListener): ClickableSpan
```

Creates a[ClickableSpan](https://developer.android.com/reference/kotlin/androidx/car/app/model/ClickableSpan)from a[OnClickListener](https://developer.android.com/reference/kotlin/androidx/car/app/model/OnClickListener).

Note that the callback relates to UI events and will be executed on the main thread using[getMainLooper](https://developer.android.com/reference/android/os/Looper.html#getMainLooper()).  

|                                                    Throws                                                     |
|---------------------------------------------------------------------------------------------------------------|-----------------------------|
| [java.lang.NullPointerException](https://developer.android.com/reference/java/lang/NullPointerException.html) | if`onClickListener`is`null` |

### equals

```
fun equals(other: Any?): Boolean
```  

### getOnClickDelegate

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.0.0)  

```
fun getOnClickDelegate(): OnClickDelegate
```

Returns the[OnClickDelegate](https://developer.android.com/reference/kotlin/androidx/car/app/model/OnClickDelegate)associated with this span.  

### hashCode

```
fun hashCode(): Int
```  

### toString

```
fun toString(): String
```