Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Nested Classes](https://developer.android.com/reference/android/widget/Filter#nestedclasses) \| [Ctors](https://developer.android.com/reference/android/widget/Filter#pubctors) \| [Methods](https://developer.android.com/reference/android/widget/Filter#pubmethods) \| [Protected Methods](https://developer.android.com/reference/android/widget/Filter#promethods) \| [Inherited Methods](https://developer.android.com/reference/android/widget/Filter#inhmethods)

# Filter

*** ** * ** ***

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

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

<br />

*** ** * ** ***

<br />

A filter constrains data with a filtering pattern.

Filters are usually created by `https://developer.android.com/reference/android/widget/Filterable` classes.

Filtering operations performed by calling `https://developer.android.com/reference/android/widget/Filter#filter(java.lang.CharSequence)` or `https://developer.android.com/reference/android/widget/Filter#filter(java.lang.CharSequence,%20android.widget.Filter.FilterListener)` are performed asynchronously. When these methods are called, a filtering request is posted in a request queue and processed later. Any call to one of these methods will cancel any previous non-executed filtering request.

<br />

**See also:**

- `https://developer.android.com/reference/android/widget/Filterable`

## Summary

| ### Nested classes ||
|---|---|
| ` interface` | `https://developer.android.com/reference/android/widget/Filter.FilterListener` <br /> Listener used to receive a notification upon completion of a filtering operation. |
| ` class` | `https://developer.android.com/reference/android/widget/Filter.FilterResults` <br /> Holds the results of a filtering operation. |

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/android/widget/Filter#Filter()() ` <br /> Creates a new asynchronous filter. |

| ### Public methods ||
|---|---|
| ` https://developer.android.com/reference/java/lang/CharSequence` | ` https://developer.android.com/reference/android/widget/Filter#convertResultToString(java.lang.Object)(https://developer.android.com/reference/java/lang/Object resultValue) ` <br /> Converts a value from the filtered set into a CharSequence. |
| ` final void` | ` https://developer.android.com/reference/android/widget/Filter#filter(java.lang.CharSequence)(https://developer.android.com/reference/java/lang/CharSequence constraint) ` <br /> Starts an asynchronous filtering operation. |
| ` final void` | ` https://developer.android.com/reference/android/widget/Filter#filter(java.lang.CharSequence,%20android.widget.Filter.FilterListener)(https://developer.android.com/reference/java/lang/CharSequence constraint, https://developer.android.com/reference/android/widget/Filter.FilterListener listener) ` <br /> Starts an asynchronous filtering operation. |

| ### Protected methods ||
|---|---|
| ` abstract https://developer.android.com/reference/android/widget/Filter.FilterResults` | ` https://developer.android.com/reference/android/widget/Filter#performFiltering(java.lang.CharSequence)(https://developer.android.com/reference/java/lang/CharSequence constraint) ` <br /> Invoked in a worker thread to filter the data according to the constraint. |
| ` abstract void` | ` https://developer.android.com/reference/android/widget/Filter#publishResults(java.lang.CharSequence,%20android.widget.Filter.FilterResults)(https://developer.android.com/reference/java/lang/CharSequence constraint, https://developer.android.com/reference/android/widget/Filter.FilterResults results) ` <br /> Invoked in the UI thread to publish the filtering results in the user interface. |

### 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*.

## Public constructors

### Filter

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

```
public Filter ()
```

<br />

Creates a new asynchronous filter.

<br />

<br />

## Public methods

### convertResultToString

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

```
public CharSequence convertResultToString (Object resultValue)
```

<br />

Converts a value from the filtered set into a CharSequence. Subclasses should override this method to convert their results. The default implementation returns an empty String for null values or the default String representation of the value.

<br />

<br />

| Parameters ||
|---|---|
| `resultValue` | `Object`: the value to convert to a CharSequence <br /> |

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

### filter

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

```
public final void filter (CharSequence constraint)
```

<br />

Starts an asynchronous filtering operation. Calling this method cancels all previous non-executed filtering requests and posts a new filtering request that will be executed later.

<br />

<br />

| Parameters ||
|---|---|
| `constraint` | `CharSequence`: the constraint used to filter the data <br /> |

**See also:**

- `https://developer.android.com/reference/android/widget/Filter#filter(java.lang.CharSequence,%20android.widget.Filter.FilterListener)`

### filter

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

```
public final void filter (CharSequence constraint, 
                Filter.FilterListener listener)
```

<br />

Starts an asynchronous filtering operation. Calling this method cancels all previous non-executed filtering requests and posts a new filtering request that will be executed later.

Upon completion, the listener is notified.

<br />

<br />

| Parameters ||
|---|---|
| `constraint` | `CharSequence`: the constraint used to filter the data <br /> |
| `listener` | `Filter.FilterListener`: a listener notified upon completion of the operation <br /> |

**See also:**

- `https://developer.android.com/reference/android/widget/Filter#filter(java.lang.CharSequence)`
- `https://developer.android.com/reference/android/widget/Filter#performFiltering(java.lang.CharSequence)`
- `https://developer.android.com/reference/android/widget/Filter#publishResults(java.lang.CharSequence,%20android.widget.Filter.FilterResults)`

## Protected methods

### performFiltering

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

```
protected abstract Filter.FilterResults performFiltering (CharSequence constraint)
```

<br />

Invoked in a worker thread to filter the data according to the constraint. Subclasses must implement this method to perform the filtering operation. Results computed by the filtering operation must be returned as a `https://developer.android.com/reference/android/widget/Filter.FilterResults` that will then be published in the UI thread through `https://developer.android.com/reference/android/widget/Filter#publishResults(java.lang.CharSequence,%20android.widget.Filter.FilterResults)`.

**Contract:** When the constraint is null, the original data must be restored.

<br />

<br />

| Parameters ||
|---|---|
| `constraint` | `CharSequence`: the constraint used to filter the data <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/widget/Filter.FilterResults` | the results of the filtering operation <br /> |

**See also:**

- `https://developer.android.com/reference/android/widget/Filter#filter(java.lang.CharSequence,%20android.widget.Filter.FilterListener)`
- `https://developer.android.com/reference/android/widget/Filter#publishResults(java.lang.CharSequence,%20android.widget.Filter.FilterResults)`
- `https://developer.android.com/reference/android/widget/Filter.FilterResults`

### publishResults

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

```
protected abstract void publishResults (CharSequence constraint, 
                Filter.FilterResults results)
```

<br />

Invoked in the UI thread to publish the filtering results in the user interface. Subclasses must implement this method to display the results computed in `https://developer.android.com/reference/android/widget/Filter#performFiltering(java.lang.CharSequence)`.

<br />

<br />

| Parameters ||
|---|---|
| `constraint` | `CharSequence`: the constraint used to filter the data <br /> |
| `results` | `Filter.FilterResults`: the results of the filtering operation <br /> |

**See also:**

- `https://developer.android.com/reference/android/widget/Filter#filter(java.lang.CharSequence,%20android.widget.Filter.FilterListener)`
- `https://developer.android.com/reference/android/widget/Filter#performFiltering(java.lang.CharSequence)`
- `https://developer.android.com/reference/android/widget/Filter.FilterResults`