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

# InputFilter.LengthFilter

*** ** * ** ***


`
public
static


class
InputFilter.LengthFilter
`


`

extends https://developer.android.com/reference/java/lang/Object


`

`


implements

https://developer.android.com/reference/android/text/InputFilter


`

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

<br />

*** ** * ** ***

This filter will constrain edits not to make the length of the text
greater than the specified length.

## Summary

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/android/text/InputFilter.LengthFilter#LengthFilter(int)(int max) ` |

| ### Public methods ||
|---|---|
| ` https://developer.android.com/reference/java/lang/CharSequence` | ` https://developer.android.com/reference/android/text/InputFilter.LengthFilter#filter(java.lang.CharSequence,%20int,%20int,%20android.text.Spanned,%20int,%20int)(https://developer.android.com/reference/java/lang/CharSequence source, int start, int end, https://developer.android.com/reference/android/text/Spanned dest, int dstart, int dend) ` This method is called when the buffer is going to replace the range `dstart ... dend` of `dest` with the new text from the range `start ... end` of `source`. |
| ` int` | ` https://developer.android.com/reference/android/text/InputFilter.LengthFilter#getMax()() ` |

| ### 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*. | ||
| From interface ` https://developer.android.com/reference/android/text/InputFilter ` |---|---| | ` abstract https://developer.android.com/reference/java/lang/CharSequence` | ` https://developer.android.com/reference/android/text/InputFilter#filter(java.lang.CharSequence,%20int,%20int,%20android.text.Spanned,%20int,%20int)(https://developer.android.com/reference/java/lang/CharSequence source, int start, int end, https://developer.android.com/reference/android/text/Spanned dest, int dstart, int dend) ` This method is called when the buffer is going to replace the range `dstart ... dend` of `dest` with the new text from the range `start ... end` of `source`. | ||

## Public constructors

### LengthFilter

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

```
public LengthFilter (int max)
```

<br />

<br />

| Parameters ||
|---|---|
| `max` | `int` <br /> |

## Public methods

### filter

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

```
public CharSequence filter (CharSequence source, 
                int start, 
                int end, 
                Spanned dest, 
                int dstart, 
                int dend)
```

This method is called when the buffer is going to replace the
range `dstart ... dend` of `dest`
with the new text from the range `start ... end`
of `source`. Return the CharSequence that you would
like to have placed there instead, including an empty string
if appropriate, or `null` to accept the original
replacement. Be careful to not to reject 0-length replacements,
as this is what happens when you delete text. Also beware that
you should not attempt to make any changes to `dest`
from this method; you may only examine it for context.

Note: If <var translate="no">source</var> is an instance of `https://developer.android.com/reference/android/text/Spanned` or
`https://developer.android.com/reference/android/text/Spannable`, the span objects in the <var translate="no">source</var> should be
copied into the filtered result (i.e. the non-null return value).
`https://developer.android.com/reference/android/text/TextUtils#copySpansFrom(android.text.Spanned,%20int,%20int,%20java.lang.Class,%20android.text.Spannable,%20int)` can be used for convenience if the
span boundary indices would be remaining identical relative to the source.

<br />

| Parameters ||
|---|---|
| `source` | `CharSequence` <br /> |
| `start` | `int` <br /> |
| `end` | `int` <br /> |
| `dest` | `Spanned` <br /> |
| `dstart` | `int` <br /> |
| `dend` | `int` <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/CharSequence` | <br /> |

### getMax

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

```
public int getMax ()
```

<br />

<br />

| Returns ||
|---|---|
| `int` | the maximum length enforced by this input filter <br /> |