# TextSelection.Builder

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

# Builder

*** ** * ** ***

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

```
class Builder
```

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

Builder used to build[TextSelection](https://developer.android.com/reference/kotlin/android/view/textclassifier/TextSelection)objects.

## Summary

|                                                                                                                                                                                                                                    Public constructors                                                                                                                                                                                                                                    ||
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| [Builder](https://developer.android.com/reference/kotlin/android/view/textclassifier/TextSelection.Builder#Builder(kotlin.Int,%20kotlin.Int))`(`startIndex:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`, `endIndex:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`)` Creates a builder used to build[TextSelection](https://developer.android.com/reference/kotlin/android/view/textclassifier/TextSelection)objects. |

|                                                                                                                                                                                                                                                                              Public methods                                                                                                                                                                                                                                                                               ||
|----------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [TextSelection](https://developer.android.com/reference/kotlin/android/view/textclassifier/TextSelection)                  | [build](https://developer.android.com/reference/kotlin/android/view/textclassifier/TextSelection.Builder#build())`()` Builds and returns[TextSelection](https://developer.android.com/reference/kotlin/android/view/textclassifier/TextSelection)object.                                                                                                                                                                                      |
| [TextSelection.Builder](https://developer.android.com/reference/kotlin/android/view/textclassifier/TextSelection.Builder#) | [setEntityType](https://developer.android.com/reference/kotlin/android/view/textclassifier/TextSelection.Builder#setEntityType(kotlin.String,%20kotlin.Float))`(`type:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, `confidenceScore:` `[Float](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-float/index.html)`)` Sets an entity type for the classified text and assigns a confidence score. |
| [TextSelection.Builder](https://developer.android.com/reference/kotlin/android/view/textclassifier/TextSelection.Builder#) | [setExtras](https://developer.android.com/reference/kotlin/android/view/textclassifier/TextSelection.Builder#setExtras(android.os.Bundle))`(`extras:` `[Bundle](https://developer.android.com/reference/kotlin/android/os/Bundle.html#)?`)` Sets the extended data.                                                                                                                                                                           |
| [TextSelection.Builder](https://developer.android.com/reference/kotlin/android/view/textclassifier/TextSelection.Builder#) | [setId](https://developer.android.com/reference/kotlin/android/view/textclassifier/TextSelection.Builder#setId(kotlin.String))`(`id:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)?`)` Sets an id for the TextSelection object.                                                                                                                                                                          |
| [TextSelection.Builder](https://developer.android.com/reference/kotlin/android/view/textclassifier/TextSelection.Builder#) | [setTextClassification](https://developer.android.com/reference/kotlin/android/view/textclassifier/TextSelection.Builder#setTextClassification(android.view.textclassifier.TextClassification))`(`textClassification:` `[TextClassification](https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassification)?`)` Sets the text classification result of the suggested selection.                               |

## Public constructors

### Builder

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

```
Builder(
    startIndex: Int, 
    endIndex: Int)
```

Creates a builder used to build[TextSelection](https://developer.android.com/reference/kotlin/android/view/textclassifier/TextSelection)objects.

|                                                                                     Parameters                                                                                      ||
|--------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `startIndex` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html):the start index of the text selection. Value is 0 or greater                               |
| `endIndex`   | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html):the end index of the text selection. Must be greater than startIndex Value is 0 or greater |

## Public methods

### build

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

```
fun build(): TextSelection
```

Builds and returns[TextSelection](https://developer.android.com/reference/kotlin/android/view/textclassifier/TextSelection)object.

|                                                                 Return                                                                 ||
|-----------------------------------------------------------------------------------------------------------|-----------------------------|
| [TextSelection](https://developer.android.com/reference/kotlin/android/view/textclassifier/TextSelection) | This value cannot be`null`. |

### setEntityType

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

```
fun setEntityType(
    type: String, 
    confidenceScore: Float
): TextSelection.Builder
```

Sets an entity type for the classified text and assigns a confidence score.

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        Parameters                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        ||
|-------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `confidenceScore` | [Float](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-float/index.html):a value from 0 (low confidence) to 1 (high confidence). 0 implies the entity does not exist for the classified text. Values greater than 1 are clamped to 1. Value is between 0.0f and 1.0f inclusive                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| `type`            | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html):This value cannot be`null`. Value is[android.view.textclassifier.TextClassifier#TYPE_UNKNOWN](https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassifier#TYPE_UNKNOWN:kotlin.String),[android.view.textclassifier.TextClassifier#TYPE_OTHER](https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassifier#TYPE_OTHER:kotlin.String),[android.view.textclassifier.TextClassifier#TYPE_EMAIL](https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassifier#TYPE_EMAIL:kotlin.String),[android.view.textclassifier.TextClassifier#TYPE_PHONE](https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassifier#TYPE_PHONE:kotlin.String),[android.view.textclassifier.TextClassifier#TYPE_ADDRESS](https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassifier#TYPE_ADDRESS:kotlin.String),[android.view.textclassifier.TextClassifier#TYPE_URL](https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassifier#TYPE_URL:kotlin.String),[android.view.textclassifier.TextClassifier#TYPE_DATE](https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassifier#TYPE_DATE:kotlin.String),[android.view.textclassifier.TextClassifier#TYPE_DATE_TIME](https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassifier#TYPE_DATE_TIME:kotlin.String),[android.view.textclassifier.TextClassifier#TYPE_FLIGHT_NUMBER](https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassifier#TYPE_FLIGHT_NUMBER:kotlin.String), android.view.textclassifier.TextClassifier.TYPE_DICTIONARY,[android.view.textclassifier.TextClassifier#TYPE_OTP](https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassifier#TYPE_OTP:kotlin.String), or[android.view.textclassifier.TextClassifier#TYPE_SMS_RETRIEVER_OTP](https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassifier#TYPE_SMS_RETRIEVER_OTP:kotlin.String) |

|                                                                         Return                                                                          ||
|----------------------------------------------------------------------------------------------------------------------------|-----------------------------|
| [TextSelection.Builder](https://developer.android.com/reference/kotlin/android/view/textclassifier/TextSelection.Builder#) | This value cannot be`null`. |

### setExtras

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

```
fun setExtras(extras: Bundle?): TextSelection.Builder
```

Sets the extended data.

|                                                      Parameters                                                      ||
|----------|------------------------------------------------------------------------------------------------------------|
| `extras` | [Bundle](https://developer.android.com/reference/kotlin/android/os/Bundle.html#)?:This value may be`null`. |

|                                                                                Return                                                                                ||
|----------------------------------------------------------------------------------------------------------------------------|------------------------------------------|
| [TextSelection.Builder](https://developer.android.com/reference/kotlin/android/view/textclassifier/TextSelection.Builder#) | this builder This value cannot be`null`. |

### setId

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

```
fun setId(id: String?): TextSelection.Builder
```

Sets an id for the TextSelection object.

|                                                    Parameters                                                    ||
|------|------------------------------------------------------------------------------------------------------------|
| `id` | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)?:This value may be`null`. |

|                                                                         Return                                                                          ||
|----------------------------------------------------------------------------------------------------------------------------|-----------------------------|
| [TextSelection.Builder](https://developer.android.com/reference/kotlin/android/view/textclassifier/TextSelection.Builder#) | This value cannot be`null`. |

### setTextClassification

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

```
fun setTextClassification(textClassification: TextClassification?): TextSelection.Builder
```

Sets the text classification result of the suggested selection. If[Request.shouldIncludeTextClassification()](https://developer.android.com/reference/kotlin/android/view/textclassifier/TextSelection.Request#shouldIncludeTextClassification())is`true`, set this value. Otherwise this value may be set to null. The intention of this method is to avoid doing expensive work if the client is not interested in such result.

|                                                                             Parameters                                                                              ||
|----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------|
| `textClassification` | [TextClassification](https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassification)?:This value may be`null`. |

|                                                                  Return                                                                  ||
|----------------------------------------------------------------------------------------------------------------------------|--------------|
| [TextSelection.Builder](https://developer.android.com/reference/kotlin/android/view/textclassifier/TextSelection.Builder#) | this builder |

**See Also**

- [android.view.textclassifier.TextSelection.Request#shouldIncludeTextClassification()](https://developer.android.com/reference/kotlin/android/view/textclassifier/TextSelection.Request#shouldIncludeTextClassification())