API Reference / Android Widgets / Filter Numeric Range
Apr. 24, 2019

Filter Numeric Range

About this widget

Filter Numeric Range is a filtering view made to filter between two numeric values. The most common interface for this is a slider.

To add a filter numeric range to your search experience, use these components:

  • Searcher: The Searcher that handles your searches.
  • FilterState: The current state of the filters.
  • FilterRangeViewModel: The logic applied to the numeric ranges.
  • NumberRangeView: The view that will render the numeric range filter.

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 attribute = Attribute("price")
    val viewModel = FilterRangeViewModel<Int>()
    val connection = ConnectionHandler()

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

        val view: NumberRangeView<Int> = MySliderNumberRangeView()

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

        searcher.searchAsync()
    }

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

Parameters

searcher
type: Searcher
Required

The Searcher that handles your searches.

1
viewModel.connectSearcher(searcher)
filterState
type: FilterState
Required

The FilterState that will hold your filters.

1
viewModel.connectFilterState(filterState)
numberRangeView
type: NumberRangeView
Required

The view that will render the numeric range filter.

1
viewModel.connectView(numberRangeView)
attribute
type: Attribute
Required

The attribute to filter.

1
2
val attribute = Attribute("price")
viewModel.connectFilterState(attribute = attribute, filterState)
bounds
type: Range?
Optional

If specified, the limits of the acceptable range within which values will be coerced.

1
NumberRangeViewModel(Range(0..10))
groupID
type: FilterGroupID
default: FilterGroupID(attribute.raw)
Optional

When specified, all created filters will be grouped under this ID and will be composed with this operator. Defaults to the attribute used, applying FilterOperator.And between filters in this group.

1
2
val groupID = FilterGroupID("price", FilterOperator.And)
viewModel.connectFilterState(price, filterState, groupID = groupID)

Did you find this page helpful?