Added in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

# TextSelectionEvent

*** ** * ** ***

Kotlin \|[Java](https://developer.android.com/reference/android/view/textclassifier/TextClassifierEvent.TextSelectionEvent "View this page in Java")

```
class TextSelectionEvent : TextClassifierEvent, Parcelable
```

|---|---|---|
| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html) |||
| ↳ | [android.view.textclassifier.TextClassifierEvent](https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassifierEvent) ||
|   | ↳ | [android.view.textclassifier.TextClassifierEvent.TextSelectionEvent](https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassifierEvent.TextSelectionEvent#) |

This class represents events that are related to the smart text selection feature.

```kotlin
// User started a selection. e.g. "York" in text "New York City, NY".
      new TextSelectionEvent.Builder(TYPE_SELECTION_STARTED)
          .setEventContext(classificationContext)
          .setEventIndex(0)
          .build();
 
      // System smart-selects a recognized entity. e.g. "New York City".
      new TextSelectionEvent.Builder(TYPE_SMART_SELECTION_MULTI)
          .setEventContext(classificationContext)
          .setResultId(textSelection.getId())
          .setRelativeWordStartIndex(-1) // Goes back one word to "New" from "York".
          .setRelativeWordEndIndex(2)    // Goes forward 2 words from "York" to start of ",".
          .setEntityTypes(textClassification.getEntity(0))
          .setScore(textClassification.getConfidenceScore(entityType))
          .setEventIndex(1)
          .build();
 
      // User resets the selection to the original selection. i.e. "York".
      new TextSelectionEvent.Builder(TYPE_SELECTION_RESET)
          .setEventContext(classificationContext)
          .setResultId(textSelection.getId())
          .setRelativeSuggestedWordStartIndex(-1) // Repeated from above.
          .setRelativeSuggestedWordEndIndex(2)    // Repeated from above.
          .setRelativeWordStartIndex(0)           // Original selection is always at (0, 1].
          .setRelativeWordEndIndex(1)
          .setEntityTypes(textClassification.getEntity(0))
          .setScore(textClassification.getConfidenceScore(entityType))
          .setEventIndex(2)
          .build();
 
      // User modified the selection. e.g. "New".
      new TextSelectionEvent.Builder(TYPE_SELECTION_MODIFIED)
          .setEventContext(classificationContext)
          .setResultId(textSelection.getId())
          .setRelativeSuggestedWordStartIndex(-1) // Repeated from above.
          .setRelativeSuggestedWordEndIndex(2)    // Repeated from above.
          .setRelativeWordStartIndex(-1)          // Goes backward one word from "York" to
          "New".
          .setRelativeWordEndIndex(0)             // Goes backward one word to exclude "York".
          .setEntityTypes(textClassification.getEntity(0))
          .setScore(textClassification.getConfidenceScore(entityType))
          .setEventIndex(3)
          .build();
 
      // Smart (contextual) actions (at indices, 0, 1, 2) presented to the user.
      // e.g. "Map", "Ride share", "Explore".
      new TextSelectionEvent.Builder(TYPE_ACTIONS_SHOWN)
          .setEventContext(classificationContext)
          .setResultId(textClassification.getId())
          .setEntityTypes(textClassification.getEntity(0))
          .setScore(textClassification.getConfidenceScore(entityType))
          .setActionIndices(0, 1, 2)
          .setEventIndex(4)
          .build();
 
      // User chooses the "Copy" action.
      new TextSelectionEvent.Builder(TYPE_COPY_ACTION)
          .setEventContext(classificationContext)
          .setResultId(textClassification.getId())
          .setEntityTypes(textClassification.getEntity(0))
          .setScore(textClassification.getConfidenceScore(entityType))
          .setEventIndex(5)
          .build();
 
      // User chooses smart action at index 1. i.e. "Ride share".
      new TextSelectionEvent.Builder(TYPE_SMART_ACTION)
          .setEventContext(classificationContext)
          .setResultId(textClassification.getId())
          .setEntityTypes(textClassification.getEntity(0))
          .setScore(textClassification.getConfidenceScore(entityType))
          .setActionIndices(1)
          .setEventIndex(5)
          .build();
 
      // Selection dismissed.
      new TextSelectionEvent.Builder(TYPE_SELECTION_DESTROYED)
          .setEventContext(classificationContext)
          .setResultId(textClassification.getId())
          .setEntityTypes(textClassification.getEntity(0))
          .setScore(textClassification.getConfidenceScore(entityType))
          .setEventIndex(6)
          .build();
  
```

<br />

## Summary

| Nested classes ||
|---|---|
|   | `https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassifierEvent.TextSelectionEvent.Builder` Builder class for `https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassifierEvent.TextSelectionEvent#`. |

| Inherited constants ||
|---|---|
| From class `https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassifierEvent` |---|---| | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassifierEvent#CATEGORY_CONVERSATION_ACTIONS:kotlin.Int` Conversation actions <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassifierEvent#CATEGORY_LANGUAGE_DETECTION:kotlin.Int` Language detection <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassifierEvent#CATEGORY_LINKIFY:kotlin.Int` Linkify <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassifierEvent#CATEGORY_SELECTION:kotlin.Int` Smart selection <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassifierEvent#TYPE_ACTIONS_GENERATED:kotlin.Int` TextClassifier generated some actions <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassifierEvent#TYPE_ACTIONS_SHOWN:kotlin.Int` Smart actions shown to the user. <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassifierEvent#TYPE_AUTO_SELECTION:kotlin.Int` Something else other than user or the default TextClassifier triggered a selection. <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassifierEvent#TYPE_COPY_ACTION:kotlin.Int` User clicked on Copy action. <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassifierEvent#TYPE_CUT_ACTION:kotlin.Int` User clicked on Cut action. <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassifierEvent#TYPE_LINKS_GENERATED:kotlin.Int` Some text links were generated. <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassifierEvent#TYPE_LINK_CLICKED:kotlin.Int` User clicked a link. <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassifierEvent#TYPE_MANUAL_REPLY:kotlin.Int` User composed a reply. <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassifierEvent#TYPE_OTHER_ACTION:kotlin.Int` User clicked on a custom action. <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassifierEvent#TYPE_OVERTYPE:kotlin.Int` User typed over the selection. <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassifierEvent#TYPE_PASTE_ACTION:kotlin.Int` User clicked on Paste action. <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassifierEvent#TYPE_SELECTION_DESTROYED:kotlin.Int` Selection is destroyed. <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassifierEvent#TYPE_SELECTION_DRAG:kotlin.Int` User dragged+dropped the selection. <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassifierEvent#TYPE_SELECTION_MODIFIED:kotlin.Int` User modified an existing selection. <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassifierEvent#TYPE_SELECTION_RESET:kotlin.Int` User reset the smart selection. <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassifierEvent#TYPE_SELECTION_STARTED:kotlin.Int` User started a new selection. <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassifierEvent#TYPE_SELECT_ALL:kotlin.Int` User clicked on Select All action <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassifierEvent#TYPE_SHARE_ACTION:kotlin.Int` User clicked on Share action. <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassifierEvent#TYPE_SMART_ACTION:kotlin.Int` User clicked on a Smart action. <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassifierEvent#TYPE_SMART_SELECTION_MULTI:kotlin.Int` Smart selection triggered spanning multiple tokens (words). <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassifierEvent#TYPE_SMART_SELECTION_SINGLE:kotlin.Int` Smart selection triggered for a single token (word). <br /> | ||
| From class `https://developer.android.com/reference/kotlin/android/os/Parcelable.html#` |---|---| | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/android/os/Parcelable.html#CONTENTS_FILE_DESCRIPTOR:kotlin.Int` Descriptor bit used with `https://developer.android.com/reference/kotlin/android/os/Parcelable.html#describeContents()`: indicates that the Parcelable object's flattened representation includes a file descriptor. <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/android/os/Parcelable.html#PARCELABLE_WRITE_RETURN_VALUE:kotlin.Int` Flag for use with `https://developer.android.com/reference/kotlin/android/os/Parcelable.html#writeToParcel(android.os.Parcel,%20kotlin.Int)`: the object being written is a return value, that is the result of a function such as "`Parcelable someFunction()`", "`void someFunction(out Parcelable)`", or "`void someFunction(inout Parcelable)`". Some implementations may want to release resources at this point. <br /> | ||

| Public methods ||
|---|---|
| [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) | `https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassifierEvent.TextSelectionEvent#getRelativeSuggestedWordEndIndex()()` Returns the relative word (exclusive) index of the end of the smart selection. |
| [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) | `https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassifierEvent.TextSelectionEvent#getRelativeSuggestedWordStartIndex()()` Returns the relative word index of the start of the smart selection. |
| [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) | `https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassifierEvent.TextSelectionEvent#getRelativeWordEndIndex()()` Returns the relative word (exclusive) index of the end of the selection. |
| [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) | `https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassifierEvent.TextSelectionEvent#getRelativeWordStartIndex()()` Returns the relative word index of the start of the selection. |
| [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | `https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassifierEvent.TextSelectionEvent#writeToParcel(android.os.Parcel,%20kotlin.Int)(dest: https://developer.android.com/reference/kotlin/android/os/Parcel.html#, flags: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)` Flatten this object in to a Parcel. |

| Inherited functions ||
|---|---|
| From class `https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassifierEvent` |---|---| | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassifierEvent#describeContents()()` Describe the kinds of special objects contained in this Parcelable instance's marshaled representation. For example, if the object will include a file descriptor in the output of `https://developer.android.com/reference/kotlin/android/os/Parcelable.html#writeToParcel(android.os.Parcel,%20kotlin.Int)`, the return value of this method must include the `https://developer.android.com/reference/kotlin/android/os/Parcelable.html#CONTENTS_FILE_DESCRIPTOR:kotlin.Int` bit. <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int-array/index.html` | `https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassifierEvent#getActionIndices()()` Returns the indices of the actions relating to this event. Actions are usually returned by the text classifier in priority order with the most preferred action at index 0. This list gives an indication of the position of the actions that are being reported. <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-array/index.html<https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html!>` | `https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassifierEvent#getEntityTypes()()` Returns an array of entity types. e.g. `https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassifier#TYPE_ADDRESS:kotlin.String`. <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassifierEvent#getEventCategory()()` Returns the event category. e.g. `https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassifierEvent#CATEGORY_SELECTION:kotlin.Int`. <br /> | | `https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassificationContext?` | `https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassifierEvent#getEventContext()()` Returns the event context. <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassifierEvent#getEventIndex()()` Returns the index of this event in the series of event it belongs to. <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassifierEvent#getEventType()()` Returns the event type. e.g. `https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassifierEvent#TYPE_SELECTION_STARTED:kotlin.Int`. <br /> | | `https://developer.android.com/reference/kotlin/android/os/Bundle.html#` | `https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassifierEvent#getExtras()()` Returns a bundle containing non-structured extra information about this event. **NOTE:**Do not modify this bundle. <br /> | | `https://developer.android.com/reference/kotlin/android/icu/util/ULocale.html#?` | `https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassifierEvent#getLocale()()` Returns the detected locale. <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html?` | `https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassifierEvent#getModelName()()` Returns the model name. <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html?` | `https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassifierEvent#getResultId()()` Returns the id of the text classifier result related to this event. <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-float-array/index.html` | `https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassifierEvent#getScores()()` Returns the scores of the suggestions. <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html` | `https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassifierEvent#toString()()` Returns a string representation of the object. <br /> | ||

| Properties ||
|---|---|
| static [Parcelable.Creator](https://developer.android.com/reference/kotlin/android/os/Parcelable.Creator.html#)\<[TextClassifierEvent.TextSelectionEvent](https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassifierEvent.TextSelectionEvent#)!\> | `https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassifierEvent.TextSelectionEvent#CREATOR:android.os.Parcelable.Creator` <br /> |

## Public methods

### getRelativeSuggestedWordEndIndex

Added in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

```
fun getRelativeSuggestedWordEndIndex(): Int
```

Returns the relative word (exclusive) index of the end of the smart selection.

### getRelativeSuggestedWordStartIndex

Added in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

```
fun getRelativeSuggestedWordStartIndex(): Int
```

Returns the relative word index of the start of the smart selection.

### getRelativeWordEndIndex

Added in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

```
fun getRelativeWordEndIndex(): Int
```

Returns the relative word (exclusive) index of the end of the selection.

### getRelativeWordStartIndex

Added in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

```
fun getRelativeWordStartIndex(): Int
```

Returns the relative word index of the start of the selection.

### writeToParcel

Added in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

```
fun writeToParcel(
    dest: Parcel, 
    flags: Int
): Unit
```

Flatten this object in to a Parcel.

| Parameters ||
|---|---|
| `dest` | [Parcel](https://developer.android.com/reference/kotlin/android/os/Parcel.html#): The Parcel in which the object should be written. This value cannot be `null`. |
| `flags` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html): Additional flags about how the object should be written. May be 0 or `https://developer.android.com/reference/kotlin/android/os/Parcelable.html#PARCELABLE_WRITE_RETURN_VALUE:kotlin.Int`. Value is either `0` or a combination of the following: - `https://developer.android.com/reference/kotlin/android/os/Parcelable.html#PARCELABLE_WRITE_RETURN_VALUE:kotlin.Int` |

## Properties

### CREATOR

Added in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

```
static val CREATOR: Parcelable.Creator<TextClassifierEvent.TextSelectionEvent!>
```