API Reference / Android Widgets / Clear Filters
Apr. 24, 2019

Clear Filters

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:

  • FilterClearInteractor: The logic for clearing refinements in the FilterState.
  • FilterState: The current state of the filters.
  • FilterClearView: The view that will render 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
class MyActivity : AppCompatActivity() {

    val client = ClientSearch(
        ApplicationID("YourApplicationID"),
        APIKey("YourAPIKey")
    )
    val index = client.initIndex(IndexName("YourIndexName"))
    val searcher = SearcherSingleIndex(index)
    val filterState = FilterState()
    val viewModel = FilterClearViewModel()
    val connection = ConnectionHandler()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        val someView = View(this)
        val view: FilterClearView = FilterClearViewImpl(someView)

        connection += searcher.connectFilterState(filterState)
        connection += viewModel.connectFilterState(filterState)
        connection += viewModel.connectView(view)

        searcher.searchAsync()
    }

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

Parameters

filterState
type: FilterState
Required

The FilterState that will hold your filters.

1
viewModel.connectFilterState(filterState)
filterClearView
type: FilterClearView
Required

The view that will render the clear filter UI.

1
viewModel.connectView(filterClearView)
groupIDs
type: List<FilterGroupID>
default: listOf()
Optional

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

1
2
val groupIDs = listOf(groupAnd("color"), groupOr("category")
viewModel.connectFilterState(filterState, groupIDs = groupIDs)   
mode
type: ClearMode
default: ClearMode.Specified
Optional

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

1
viewModel.connectFilterState(filterState, groupIDs, mode = ClearMode.Except)    

Did you find this page helpful?