# 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)

*** ** * ** ***


```
@RequiresCarApi(value = 2)
@CarProtocol
public final class ClickableSpan extends CarSpan
```

<br />

|---|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.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/androidx/car/app/model/CarSpan) ||
|   |   | ↳ | [androidx.car.app.model.ClickableSpan](https://developer.android.com/reference/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, `https://developer.android.com/reference/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 `https://developer.android.com/reference/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:

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

## Summary

| ### Public methods |
|---|---|
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/ClickableSpan` | `https://developer.android.com/reference/androidx/car/app/model/ClickableSpan#create(androidx.car.app.model.OnClickListener)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/OnClickListener onClickListener)` Creates a `https://developer.android.com/reference/androidx/car/app/model/ClickableSpan` from a `https://developer.android.com/reference/androidx/car/app/model/OnClickListener`. |
| `boolean` | `https://developer.android.com/reference/androidx/car/app/model/ClickableSpan#equals(java.lang.Object)(@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/Object.html other)` |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/OnClickDelegate` | `https://developer.android.com/reference/androidx/car/app/model/ClickableSpan#getOnClickDelegate()()` Returns the `https://developer.android.com/reference/androidx/car/app/model/OnClickDelegate` associated with this span. |
| `int` | `https://developer.android.com/reference/androidx/car/app/model/ClickableSpan#hashCode()()` |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/car/app/model/ClickableSpan#toString()()` |

| ### Inherited methods |
|---|
| From [androidx.car.app.model.CarSpan](https://developer.android.com/reference/androidx/car/app/model/CarSpan) |---|---| | `void` | `https://developer.android.com/reference/androidx/car/app/model/CarSpan#updateDrawState(android.text.TextPaint)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/text/TextPaint.html tp)` | |
| From [android.text.style.CharacterStyle](https://developer.android.com/reference/android/text/style/CharacterStyle.html) |---|---| | `https://developer.android.com/reference/android/text/style/CharacterStyle.html` | `https://developer.android.com/reference/android/text/style/CharacterStyle.html#getUnderlying()()` | | `abstract void` | `https://developer.android.com/reference/android/text/style/CharacterStyle.html#updateDrawState(android.text.TextPaint)(https://developer.android.com/reference/android/text/TextPaint.html p)` | | `static https://developer.android.com/reference/android/text/style/CharacterStyle.html` | `https://developer.android.com/reference/android/text/style/CharacterStyle.html#wrap(android.text.style.CharacterStyle)(https://developer.android.com/reference/android/text/style/CharacterStyle.html cs)` | |

## Public methods

### create

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

```
public static @NonNull ClickableSpan create(@NonNull OnClickListener onClickListener)
```

Creates a `https://developer.android.com/reference/androidx/car/app/model/ClickableSpan` from a `https://developer.android.com/reference/androidx/car/app/model/OnClickListener`.

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

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

### equals

```
public boolean equals(@Nullable Object other)
```

### getOnClickDelegate

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

```
public @NonNull OnClickDelegate getOnClickDelegate()
```

Returns the `https://developer.android.com/reference/androidx/car/app/model/OnClickDelegate` associated with this span.

### hashCode

```
public int hashCode()
```

### toString

```
public @NonNull String toString()
```