Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Fields](https://developer.android.com/reference/android/text/Selection#lfields) \| [Methods](https://developer.android.com/reference/android/text/Selection#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/text/Selection#inhmethods)

# Selection

*** ** * ** ***

` public class Selection `   
` extends https://developer.android.com/reference/java/lang/Object ` ` `

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.text.Selection |

<br />

*** ** * ** ***

Utility class for manipulating cursors and selections in CharSequences. A cursor is a selection where the start and end are at the same offset.

## Summary

| ### Fields ||
|---|---|
| ` public static final https://developer.android.com/reference/java/lang/Object` | `https://developer.android.com/reference/android/text/Selection#SELECTION_END` <br /> |
| ` public static final https://developer.android.com/reference/java/lang/Object` | `https://developer.android.com/reference/android/text/Selection#SELECTION_START` <br /> |

| ### Public methods ||
|---|---|
| ` static boolean` | ` https://developer.android.com/reference/android/text/Selection#extendDown(android.text.Spannable,%20android.text.Layout)(https://developer.android.com/reference/android/text/Spannable text, https://developer.android.com/reference/android/text/Layout layout) ` Move the selection end to the buffer offset physically below the current selection end. |
| ` static boolean` | ` https://developer.android.com/reference/android/text/Selection#extendLeft(android.text.Spannable,%20android.text.Layout)(https://developer.android.com/reference/android/text/Spannable text, https://developer.android.com/reference/android/text/Layout layout) ` Move the selection end to the buffer offset physically to the left of the current selection end. |
| ` static boolean` | ` https://developer.android.com/reference/android/text/Selection#extendRight(android.text.Spannable,%20android.text.Layout)(https://developer.android.com/reference/android/text/Spannable text, https://developer.android.com/reference/android/text/Layout layout) ` Move the selection end to the buffer offset physically to the right of the current selection end. |
| ` static final void` | ` https://developer.android.com/reference/android/text/Selection#extendSelection(android.text.Spannable,%20int)(https://developer.android.com/reference/android/text/Spannable text, int index) ` Move the selection edge to offset `index`. |
| ` static boolean` | ` https://developer.android.com/reference/android/text/Selection#extendToLeftEdge(android.text.Spannable,%20android.text.Layout)(https://developer.android.com/reference/android/text/Spannable text, https://developer.android.com/reference/android/text/Layout layout) ` |
| ` static boolean` | ` https://developer.android.com/reference/android/text/Selection#extendToParagraphEnd(android.text.Spannable)(https://developer.android.com/reference/android/text/Spannable text) ` Extend the selection to the closest paragraph end offset. |
| ` static boolean` | ` https://developer.android.com/reference/android/text/Selection#extendToParagraphStart(android.text.Spannable)(https://developer.android.com/reference/android/text/Spannable text) ` Extend the selection to the closest paragraph start offset. |
| ` static boolean` | ` https://developer.android.com/reference/android/text/Selection#extendToRightEdge(android.text.Spannable,%20android.text.Layout)(https://developer.android.com/reference/android/text/Spannable text, https://developer.android.com/reference/android/text/Layout layout) ` |
| ` static boolean` | ` https://developer.android.com/reference/android/text/Selection#extendUp(android.text.Spannable,%20android.text.Layout)(https://developer.android.com/reference/android/text/Spannable text, https://developer.android.com/reference/android/text/Layout layout) ` Move the selection end to the buffer offset physically above the current selection end. |
| ` static final int` | ` https://developer.android.com/reference/android/text/Selection#getSelectionEnd(java.lang.CharSequence)(https://developer.android.com/reference/java/lang/CharSequence text) ` Return the offset of the selection edge or cursor, or -1 if there is no selection or cursor. |
| ` static final int` | ` https://developer.android.com/reference/android/text/Selection#getSelectionStart(java.lang.CharSequence)(https://developer.android.com/reference/java/lang/CharSequence text) ` Return the offset of the selection anchor or cursor, or -1 if there is no selection or cursor. |
| ` static boolean` | ` https://developer.android.com/reference/android/text/Selection#moveDown(android.text.Spannable,%20android.text.Layout)(https://developer.android.com/reference/android/text/Spannable text, https://developer.android.com/reference/android/text/Layout layout) ` Move the cursor to the buffer offset physically below the current offset, to the end of the buffer if it is on the bottom line but not at the end, or return false if the cursor is already at the end of the buffer. |
| ` static boolean` | ` https://developer.android.com/reference/android/text/Selection#moveLeft(android.text.Spannable,%20android.text.Layout)(https://developer.android.com/reference/android/text/Spannable text, https://developer.android.com/reference/android/text/Layout layout) ` Move the cursor to the buffer offset physically to the left of the current offset, or return false if the cursor is already at the left edge of the line and there is not another line to move it to. |
| ` static boolean` | ` https://developer.android.com/reference/android/text/Selection#moveRight(android.text.Spannable,%20android.text.Layout)(https://developer.android.com/reference/android/text/Spannable text, https://developer.android.com/reference/android/text/Layout layout) ` Move the cursor to the buffer offset physically to the right of the current offset, or return false if the cursor is already at at the right edge of the line and there is not another line to move it to. |
| ` static boolean` | ` https://developer.android.com/reference/android/text/Selection#moveToLeftEdge(android.text.Spannable,%20android.text.Layout)(https://developer.android.com/reference/android/text/Spannable text, https://developer.android.com/reference/android/text/Layout layout) ` |
| ` static boolean` | ` https://developer.android.com/reference/android/text/Selection#moveToParagraphEnd(android.text.Spannable,%20android.text.Layout)(https://developer.android.com/reference/android/text/Spannable text, https://developer.android.com/reference/android/text/Layout layout) ` Move the cursor to the closest paragraph end offset. |
| ` static boolean` | ` https://developer.android.com/reference/android/text/Selection#moveToParagraphStart(android.text.Spannable,%20android.text.Layout)(https://developer.android.com/reference/android/text/Spannable text, https://developer.android.com/reference/android/text/Layout layout) ` Move the cursor to the closest paragraph start offset. |
| ` static boolean` | ` https://developer.android.com/reference/android/text/Selection#moveToRightEdge(android.text.Spannable,%20android.text.Layout)(https://developer.android.com/reference/android/text/Spannable text, https://developer.android.com/reference/android/text/Layout layout) ` |
| ` static boolean` | ` https://developer.android.com/reference/android/text/Selection#moveUp(android.text.Spannable,%20android.text.Layout)(https://developer.android.com/reference/android/text/Spannable text, https://developer.android.com/reference/android/text/Layout layout) ` Move the cursor to the buffer offset physically above the current offset, to the beginning if it is on the top line but not at the start, or return false if the cursor is already on the top line. |
| ` static final void` | ` https://developer.android.com/reference/android/text/Selection#removeSelection(android.text.Spannable)(https://developer.android.com/reference/android/text/Spannable text) ` Remove the selection or cursor, if any, from the text. |
| ` static final void` | ` https://developer.android.com/reference/android/text/Selection#selectAll(android.text.Spannable)(https://developer.android.com/reference/android/text/Spannable text) ` Select the entire text. |
| ` static void` | ` https://developer.android.com/reference/android/text/Selection#setSelection(android.text.Spannable,%20int,%20int)(https://developer.android.com/reference/android/text/Spannable text, int start, int stop) ` Set the selection anchor to `start` and the selection edge to `stop`. |
| ` static final void` | ` https://developer.android.com/reference/android/text/Selection#setSelection(android.text.Spannable,%20int)(https://developer.android.com/reference/android/text/Spannable text, int index) ` Move the cursor to offset `index`. |

### Inherited methods

From class ` https://developer.android.com/reference/java/lang/Object ` ` https://developer.android.com/reference/java/lang/Object` ` https://developer.android.com/reference/java/lang/Object#clone()() `

Creates and returns a copy of this object.
` boolean` ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) `

Indicates whether some other object is "equal to" this one.
` void` ` 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 https://developer.android.com/reference/java/lang/Class<?>` ` https://developer.android.com/reference/java/lang/Object#getClass()() `

Returns the runtime class of this `Object`.
` int` ` https://developer.android.com/reference/java/lang/Object#hashCode()() `

Returns a hash code value for the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#notify()() `

Wakes up a single thread that is waiting on this object's monitor.
` final void` ` https://developer.android.com/reference/java/lang/Object#notifyAll()() `

Wakes up all threads that are waiting on this object's monitor.
` https://developer.android.com/reference/java/lang/String` ` https://developer.android.com/reference/java/lang/Object#toString()() `

Returns a string representation of the object.
` final void` ` 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` ` 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` ` 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*.

## Fields

### SELECTION_END

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

```
public static final Object SELECTION_END
```

<br />

<br />

### SELECTION_START

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

```
public static final Object SELECTION_START
```

<br />

<br />

## Public methods

### extendDown

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

```
public static boolean extendDown (Spannable text, 
                Layout layout)
```

Move the selection end to the buffer offset physically below the current selection end.

<br />

| Parameters ||
|---|---|
| `text` | `Spannable` <br /> |
| `layout` | `Layout` <br /> |

| Returns ||
|---|---|
| `boolean` | <br /> |

### extendLeft

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

```
public static boolean extendLeft (Spannable text, 
                Layout layout)
```

Move the selection end to the buffer offset physically to the left of the current selection end.

<br />

| Parameters ||
|---|---|
| `text` | `Spannable` <br /> |
| `layout` | `Layout` <br /> |

| Returns ||
|---|---|
| `boolean` | <br /> |

### extendRight

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

```
public static boolean extendRight (Spannable text, 
                Layout layout)
```

Move the selection end to the buffer offset physically to the right of the current selection end.

<br />

| Parameters ||
|---|---|
| `text` | `Spannable` <br /> |
| `layout` | `Layout` <br /> |

| Returns ||
|---|---|
| `boolean` | <br /> |

### extendSelection

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

```
public static final void extendSelection (Spannable text, 
                int index)
```

Move the selection edge to offset `index`.

<br />

| Parameters ||
|---|---|
| `text` | `Spannable` <br /> |
| `index` | `int` <br /> |

### extendToLeftEdge

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

```
public static boolean extendToLeftEdge (Spannable text, 
                Layout layout)
```

<br />

<br />

| Parameters ||
|---|---|
| `text` | `Spannable` <br /> |
| `layout` | `Layout` <br /> |

| Returns ||
|---|---|
| `boolean` | <br /> |

### extendToParagraphEnd

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

```
public static boolean extendToParagraphEnd (Spannable text)
```

Extend the selection to the closest paragraph end offset.

<br />

| Parameters ||
|---|---|
| `text` | `Spannable`: the spannable text. This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `boolean` | true if the selection is extended, otherwise false <br /> |

### extendToParagraphStart

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

```
public static boolean extendToParagraphStart (Spannable text)
```

Extend the selection to the closest paragraph start offset.

<br />

| Parameters ||
|---|---|
| `text` | `Spannable`: the spannable text. This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `boolean` | true if the selection is extended, otherwise false <br /> |

### extendToRightEdge

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

```
public static boolean extendToRightEdge (Spannable text, 
                Layout layout)
```

<br />

<br />

| Parameters ||
|---|---|
| `text` | `Spannable` <br /> |
| `layout` | `Layout` <br /> |

| Returns ||
|---|---|
| `boolean` | <br /> |

### extendUp

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

```
public static boolean extendUp (Spannable text, 
                Layout layout)
```

Move the selection end to the buffer offset physically above the current selection end.

<br />

| Parameters ||
|---|---|
| `text` | `Spannable` <br /> |
| `layout` | `Layout` <br /> |

| Returns ||
|---|---|
| `boolean` | <br /> |

### getSelectionEnd

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

```
public static final int getSelectionEnd (CharSequence text)
```

Return the offset of the selection edge or cursor, or -1 if there is no selection or cursor.

<br />

| Parameters ||
|---|---|
| `text` | `CharSequence` <br /> |

| Returns ||
|---|---|
| `int` | <br /> |

### getSelectionStart

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

```
public static final int getSelectionStart (CharSequence text)
```

Return the offset of the selection anchor or cursor, or -1 if there is no selection or cursor.

<br />

| Parameters ||
|---|---|
| `text` | `CharSequence` <br /> |

| Returns ||
|---|---|
| `int` | <br /> |

### moveDown

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

```
public static boolean moveDown (Spannable text, 
                Layout layout)
```

Move the cursor to the buffer offset physically below the current offset, to the end of the buffer if it is on the bottom line but not at the end, or return false if the cursor is already at the end of the buffer.

<br />

| Parameters ||
|---|---|
| `text` | `Spannable` <br /> |
| `layout` | `Layout` <br /> |

| Returns ||
|---|---|
| `boolean` | <br /> |

### moveLeft

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

```
public static boolean moveLeft (Spannable text, 
                Layout layout)
```

Move the cursor to the buffer offset physically to the left of the current offset, or return false if the cursor is already at the left edge of the line and there is not another line to move it to.

<br />

| Parameters ||
|---|---|
| `text` | `Spannable` <br /> |
| `layout` | `Layout` <br /> |

| Returns ||
|---|---|
| `boolean` | <br /> |

### moveRight

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

```
public static boolean moveRight (Spannable text, 
                Layout layout)
```

Move the cursor to the buffer offset physically to the right of the current offset, or return false if the cursor is already at at the right edge of the line and there is not another line to move it to.

<br />

| Parameters ||
|---|---|
| `text` | `Spannable` <br /> |
| `layout` | `Layout` <br /> |

| Returns ||
|---|---|
| `boolean` | <br /> |

### moveToLeftEdge

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

```
public static boolean moveToLeftEdge (Spannable text, 
                Layout layout)
```

<br />

<br />

| Parameters ||
|---|---|
| `text` | `Spannable` <br /> |
| `layout` | `Layout` <br /> |

| Returns ||
|---|---|
| `boolean` | <br /> |

### moveToParagraphEnd

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

```
public static boolean moveToParagraphEnd (Spannable text, 
                Layout layout)
```

Move the cursor to the closest paragraph end offset.

<br />

| Parameters ||
|---|---|
| `text` | `Spannable`: the spannable text. This value cannot be `null`. <br /> |
| `layout` | `Layout`: layout to be used for drawing. This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `boolean` | true if the cursor is moved, otherwise false. <br /> |

### moveToParagraphStart

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

```
public static boolean moveToParagraphStart (Spannable text, 
                Layout layout)
```

Move the cursor to the closest paragraph start offset.

<br />

| Parameters ||
|---|---|
| `text` | `Spannable`: the spannable text. This value cannot be `null`. <br /> |
| `layout` | `Layout`: layout to be used for drawing. This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `boolean` | true if the cursor is moved, otherwise false. <br /> |

### moveToRightEdge

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

```
public static boolean moveToRightEdge (Spannable text, 
                Layout layout)
```

<br />

<br />

| Parameters ||
|---|---|
| `text` | `Spannable` <br /> |
| `layout` | `Layout` <br /> |

| Returns ||
|---|---|
| `boolean` | <br /> |

### moveUp

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

```
public static boolean moveUp (Spannable text, 
                Layout layout)
```

Move the cursor to the buffer offset physically above the current offset, to the beginning if it is on the top line but not at the start, or return false if the cursor is already on the top line.

<br />

| Parameters ||
|---|---|
| `text` | `Spannable` <br /> |
| `layout` | `Layout` <br /> |

| Returns ||
|---|---|
| `boolean` | <br /> |

### removeSelection

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

```
public static final void removeSelection (Spannable text)
```

Remove the selection or cursor, if any, from the text.

<br />

| Parameters ||
|---|---|
| `text` | `Spannable` <br /> |

### selectAll

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

```
public static final void selectAll (Spannable text)
```

Select the entire text.

<br />

| Parameters ||
|---|---|
| `text` | `Spannable` <br /> |

### setSelection

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

```
public static void setSelection (Spannable text, 
                int start, 
                int stop)
```

Set the selection anchor to `start` and the selection edge to `stop`.

<br />

| Parameters ||
|---|---|
| `text` | `Spannable` <br /> |
| `start` | `int` <br /> |
| `stop` | `int` <br /> |

### setSelection

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

```
public static final void setSelection (Spannable text, 
                int index)
```

Move the cursor to offset `index`.

<br />

| Parameters ||
|---|---|
| `text` | `Spannable` <br /> |
| `index` | `int` <br /> |