Added in API level 1

Filter


abstract class Filter
kotlin.Any
   ↳ android.widget.Filter

A filter constrains data with a filtering pattern.

Filters are usually created by android.widget.Filterable classes.

Filtering operations performed by calling filter(java.lang.CharSequence) or filter(java.lang.CharSequence,android.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.

Summary

Nested classes
abstract

Listener used to receive a notification upon completion of a filtering operation.

open

Holds the results of a filtering operation.

Public constructors

Creates a new asynchronous filter.

Public methods
open CharSequence!
convertResultToString(resultValue: Any!)

Converts a value from the filtered set into a CharSequence.

Unit
filter(constraint: CharSequence!)

Starts an asynchronous filtering operation.

Unit
filter(constraint: CharSequence!, listener: Filter.FilterListener!)

Starts an asynchronous filtering operation.

Protected methods
abstract Filter.FilterResults!

Invoked in a worker thread to filter the data according to the constraint.

abstract Unit

Invoked in the UI thread to publish the filtering results in the user interface.

Public constructors

Filter

Added in API level 1
Filter()

Creates a new asynchronous filter.

Public methods

convertResultToString

Added in API level 1
open fun convertResultToString(resultValue: Any!): CharSequence!

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.

Parameters
resultValue Any!: the value to convert to a CharSequence
Return
CharSequence! a CharSequence representing the value

filter

Added in API level 1
fun filter(constraint: CharSequence!): Unit

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.

Parameters
constraint CharSequence!: the constraint used to filter the data

filter

Added in API level 1
fun filter(
    constraint: CharSequence!,
    listener: Filter.FilterListener!
): Unit

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.

Parameters
constraint CharSequence!: the constraint used to filter the data
listener Filter.FilterListener!: a listener notified upon completion of the operation

Protected methods

performFiltering

Added in API level 1
protected abstract fun performFiltering(constraint: CharSequence!): Filter.FilterResults!

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 android.widget.Filter.FilterResults that will then be published in the UI thread through publishResults(java.lang.CharSequence,android.widget.Filter.FilterResults).

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

Parameters
constraint CharSequence!: the constraint used to filter the data
Return
Filter.FilterResults! the results of the filtering operation

publishResults

Added in API level 1
protected abstract fun publishResults(
    constraint: CharSequence!,
    results: Filter.FilterResults!
): Unit

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 performFiltering.

Parameters
constraint CharSequence!: the constraint used to filter the data
results Filter.FilterResults!: the results of the filtering operation