API Reference
/
Android Widgets
/
Filter Numeric Range
Sep. 02, 2020
Filter Numeric Range
Widget signature
FilterRangeConnector( filterState: FilterState, attribute: Attribute, bounds: ClosedRange<T>?, range: ClosedRange<T>? )
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.
Examples
Copy
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
class MyActivity : AppCompatActivity() {
val client = ClientSearch(
ApplicationID("YourApplicationID"),
APIKey("YourAPIKey")
)
val index = client.initIndex(IndexName("YourIndexName"))
val searcher = SearcherSingleIndex(index)
val price = Attribute("price")
val groupID = FilterGroupID(price)
val primaryBounds = 0..15
val initialRange = 0..15
val filters = filters {
group(groupID) {
range(price, initialRange)
}
}
val filterState = FilterState(filters)
val range = FilterRangeConnector(
filterState = filterState,
attribute = price,
range = initialRange,
bounds = primaryBounds
)
val connection = ConnectionHandler(range, searcher.connectFilterState(filterState))
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val view: NumberRangeView<Int> = MyNumberRangeView(textLabel) // your `NumberRangeView<T>` implementation
connection += range.connectView(view)
searcher.searchAsync()
}
override fun onDestroy() {
super.onDestroy()
connection.disconnect()
searcher.cancel()
}
}
Low-level API
If you want to fully control the Filter Numeric Range components and connect them manually, use the following components:
Searcher
: TheSearcher
that handles your searches.FilterState
: The current state of the filters.FilterRangeViewModel
: The logic applied to the numeric ranges.NumberRangeView
: The view that renders the numeric range filter.
Copy
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
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> = MyNumberRangeView(textLabel) // your `NumberRangeView<T>` implementation
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
filterState
|
type: FilterState
Required
The |
attribute
|
type: Attribute
Required
The attribute to filter. |
bounds
|
type: ClosedRange<T>?
Optional
The limits of the acceptable range within which values are coerced. |
range
|
type: ClosedRange<T>?
Optional
The range of values within the bounds. |
View
view
|
type: NumberRangeView
Required
The view that renders the numeric range filter. |
||
Copy
|