# TextSelection.Builder

Added in[API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Summary:[Ctors](https://developer.android.com/reference/android/view/textclassifier/TextSelection.Builder#pubctors)\|[Methods](https://developer.android.com/reference/android/view/textclassifier/TextSelection.Builder#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/android/view/textclassifier/TextSelection.Builder#inhmethods)  

# TextSelection.Builder

*** ** * ** ***

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

`
public
static
final

class
TextSelection.Builder
`  
`

extends `[Object](https://developer.android.com/reference/java/lang/Object)`


``


`

|---|---------------------------------------------------|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.view.textclassifier.TextSelection.Builder |

<br />

*** ** * ** ***

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

## Summary

|                                                                                                                                          ### Public constructors                                                                                                                                          ||
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| ` `[Builder](https://developer.android.com/reference/android/view/textclassifier/TextSelection.Builder#Builder(int,%20int))`(int startIndex, int endIndex) ` Creates a builder used to build[TextSelection](https://developer.android.com/reference/android/view/textclassifier/TextSelection)objects. |

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

| ### Inherited methods |
|-----------------------|---|
| From class` `[java.lang.Object](https://developer.android.com/reference/java/lang/Object)` ` |--------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` `[Object](https://developer.android.com/reference/java/lang/Object)          | ` `[clone](https://developer.android.com/reference/java/lang/Object#clone())`() ` Creates and returns a copy of this object.                                                                                                                                                      | | ` boolean`                                                                     | ` `[equals](https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` obj) ` Indicates whether some other object is "equal to" this one.                                           | | ` void`                                                                        | ` `[finalize](https://developer.android.com/reference/java/lang/Object#finalize())`() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.                                                          | | ` final `[Class](https://developer.android.com/reference/java/lang/Class)`<?>` | ` `[getClass](https://developer.android.com/reference/java/lang/Object#getClass())`() ` Returns the runtime class of this`Object`.                                                                                                                                                | | ` int`                                                                         | ` `[hashCode](https://developer.android.com/reference/java/lang/Object#hashCode())`() ` Returns a hash code value for the object.                                                                                                                                                 | | ` final void`                                                                  | ` `[notify](https://developer.android.com/reference/java/lang/Object#notify())`() ` Wakes up a single thread that is waiting on this object's monitor.                                                                                                                            | | ` final void`                                                                  | ` `[notifyAll](https://developer.android.com/reference/java/lang/Object#notifyAll())`() ` Wakes up all threads that are waiting on this object's monitor.                                                                                                                         | | ` `[String](https://developer.android.com/reference/java/lang/String)          | ` `[toString](https://developer.android.com/reference/java/lang/Object#toString())`() ` Returns a string representation of the object.                                                                                                                                            | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long,%20int))`(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed. | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long))`(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed.                   | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait())`() ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*.                                                                                             | ||

## Public constructors

### Builder

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

```
public Builder (int startIndex, 
                int endIndex)
```

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

<br />

|                                                       Parameters                                                       ||
|--------------|----------------------------------------------------------------------------------------------------------|
| `startIndex` | `int`: the start index of the text selection. Value is 0 or greater <br />                               |
| `endIndex`   | `int`: the end index of the text selection. Must be greater than startIndex Value is 0 or greater <br /> |

## Public methods

### build

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

```
public TextSelection build ()
```

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

<br />

|                                                                Returns                                                                 ||
|----------------------------------------------------------------------------------------------------|------------------------------------|
| [TextSelection](https://developer.android.com/reference/android/view/textclassifier/TextSelection) | This value cannot be`null`. <br /> |

### setEntityType

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

```
public TextSelection.Builder setEntityType (String type, 
                float confidenceScore)
```

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

<br />

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          Parameters                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           ||
|-------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `type`            | `String`: This value cannot be`null`. Value is[TextClassifier.TYPE_UNKNOWN](https://developer.android.com/reference/android/view/textclassifier/TextClassifier#TYPE_UNKNOWN),[TextClassifier.TYPE_OTHER](https://developer.android.com/reference/android/view/textclassifier/TextClassifier#TYPE_OTHER),[TextClassifier.TYPE_EMAIL](https://developer.android.com/reference/android/view/textclassifier/TextClassifier#TYPE_EMAIL),[TextClassifier.TYPE_PHONE](https://developer.android.com/reference/android/view/textclassifier/TextClassifier#TYPE_PHONE),[TextClassifier.TYPE_ADDRESS](https://developer.android.com/reference/android/view/textclassifier/TextClassifier#TYPE_ADDRESS),[TextClassifier.TYPE_URL](https://developer.android.com/reference/android/view/textclassifier/TextClassifier#TYPE_URL),[TextClassifier.TYPE_DATE](https://developer.android.com/reference/android/view/textclassifier/TextClassifier#TYPE_DATE),[TextClassifier.TYPE_DATE_TIME](https://developer.android.com/reference/android/view/textclassifier/TextClassifier#TYPE_DATE_TIME),[TextClassifier.TYPE_FLIGHT_NUMBER](https://developer.android.com/reference/android/view/textclassifier/TextClassifier#TYPE_FLIGHT_NUMBER), android.view.textclassifier.TextClassifier.TYPE_DICTIONARY,[TextClassifier.TYPE_OTP](https://developer.android.com/reference/android/view/textclassifier/TextClassifier#TYPE_OTP), or[TextClassifier.TYPE_SMS_RETRIEVER_OTP](https://developer.android.com/reference/android/view/textclassifier/TextClassifier#TYPE_SMS_RETRIEVER_OTP) <br /> |
| `confidenceScore` | `float`: 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 <br />                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |

|                                                                        Returns                                                                         ||
|--------------------------------------------------------------------------------------------------------------------|------------------------------------|
| [TextSelection.Builder](https://developer.android.com/reference/android/view/textclassifier/TextSelection.Builder) | This value cannot be`null`. <br /> |

### setExtras

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

```
public TextSelection.Builder setExtras (Bundle extras)
```

Sets the extended data.

<br />

|                     Parameters                      ||
|----------|-------------------------------------------|
| `extras` | `Bundle`: This value may be`null`. <br /> |

|                                                                               Returns                                                                               ||
|--------------------------------------------------------------------------------------------------------------------|-------------------------------------------------|
| [TextSelection.Builder](https://developer.android.com/reference/android/view/textclassifier/TextSelection.Builder) | this builder This value cannot be`null`. <br /> |

### setId

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

```
public TextSelection.Builder setId (String id)
```

Sets an id for the TextSelection object.

<br />

|                   Parameters                    ||
|------|-------------------------------------------|
| `id` | `String`: This value may be`null`. <br /> |

|                                                                        Returns                                                                         ||
|--------------------------------------------------------------------------------------------------------------------|------------------------------------|
| [TextSelection.Builder](https://developer.android.com/reference/android/view/textclassifier/TextSelection.Builder) | This value cannot be`null`. <br /> |

### setTextClassification

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

```
public TextSelection.Builder setTextClassification (TextClassification textClassification)
```

Sets the text classification result of the suggested selection. If[Request.shouldIncludeTextClassification()](https://developer.android.com/reference/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.

<br />

|                                 Parameters                                  ||
|----------------------|-------------------------------------------------------|
| `textClassification` | `TextClassification`: This value may be`null`. <br /> |

|                                                                 Returns                                                                 ||
|--------------------------------------------------------------------------------------------------------------------|---------------------|
| [TextSelection.Builder](https://developer.android.com/reference/android/view/textclassifier/TextSelection.Builder) | this builder <br /> |

**See also:**

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