API Reference / Android Widgets / Clear Filters
Widget signature
FilterClearConnector(
  filterState: FilterState,
  groupIDs: List<FilterGroupID>,
  mode: ClearMode,
  viewModel: FilterClearViewModel
)

About this widget

ClearFilters lets the user clear all refinements that are currently active within the given FilterState.

To add ClearFilters to your search experience, use these components:

  • FilterClearViewModel: The logic for clearing refinements in the FilterState.
  • FilterState: The current state of the filters.
  • FilterClearView: The view that renders the clear filter UI.

Examples

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
class MyActivity : AppCompatActivity() {
    val client = ClientSearch(
        ApplicationID("YourApplicationID"),
        APIKey("YourAPIKey")
    )
    val index = client.initIndex(IndexName("YourIndexName"))
    val searcher = SearcherSingleIndex(index)
    val color = Attribute("color")
    val category = Attribute("category")
    val groupColor = groupOr(color)
    val groupCategory = groupOr(category)
    val filters = filters {
        group(groupColor) {
            facet(color, "red")
            facet(color, "green")
        }
        group(groupCategory) {
            facet(category, "shoe")
        }
    }
    val filterState = FilterState(filters)
    val clearAll = FilterClearConnector(filterState = filterState)
    val clearSpecified = FilterClearConnector(
        filterState = filterState,
        groupIDs = listOf(groupColor),
        mode = ClearMode.Specified
    )
    val clearExcept = FilterClearConnector(
        filterState = filterState,
        groupIDs = listOf(groupColor),
        mode = ClearMode.Except
    )
    val connection = ConnectionHandler(
        clearSpecified, clearExcept, searcher.connectFilterState(filterState)
    )

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        connection += clearAll.connectView(FilterClearViewImpl(filtersClearAll))
        connection += clearSpecified.connectView(FilterClearViewImpl(buttonClearSpecified))
        connection += clearExcept.connectView(FilterClearViewImpl(buttonClearExcept))
        searcher.searchAsync()
    }

    override fun onDestroy() {
        super.onDestroy()
        searcher.cancel()
        connection.disconnect()
    }
}

Parameters

filterState
type: FilterState
Required

The FilterState that will hold your filters.

groupIDs
type: List<FilterGroupID>
default: listOf()
Optional

The groupIDs of filters to clear. All filters will be cleared if unspecified.

mode
type: ClearMode
default: ClearMode.Specified
Optional

Whether we should clear the Specified filters or all filters Except them.

viewModel
type: FilterClearViewModel
default: FilterClearViewModel()
Optional

The logic for clearing refinements in the FilterState.

View

view
type: FilterClearView
Required

The view that renders the clear filter UI.

1
2
val view = FilterClearViewImpl(myButton) // using your own Android view
filterClearConnector.connectView(view)

Did you find this page helpful?