API Reference / Android Widgets / toggles
Apr. 11, 2019
Widget signature
<com.algolia.instantsearch.ui.views.OneValueToggle
  android:id="@+id/oneValueToggle"
  algolia:attribute="string"
  algolia:value="string"

  <!-- Optional parameters -->
  algolia:template="string"
  algolia:variant="string"
  algolia:autoHide="boolean"
/>

<com.algolia.instantsearch.ui.views.TwoValuesToggle
  android:id="@+id/twoValuesToggle"
  algolia:attribute="string"
  algolia:valueOn="string"
  algolia:valueOff="string"

  <!-- Optional parameters -->
  algolia:template="string"
  algolia:variant="string"
  algolia:autoHide="boolean"
/>

About this widget

Toggles are widgets for filtering faceted attributes. There currently are two kinds of Toggles:

  • OneValueToggle: a SwitchCompat-based widget that toggles between filtering or not filtering a specific value for its attribute.
  • TwoValuesToggle: a SwitchCompat-based widget that toggles between filtering an one or another value for its attribute.

Examples

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<com.algolia.instantsearch.ui.views.OneValueToggle
    android:id="@+id/oneValueToggle"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    algolia:attribute="category"
    algolia:value="book"
    algolia:template="filter {name} for {value}: {isRefined}"/>

<com.algolia.instantsearch.ui.views.TwoValuesToggle
    android:id="@+id/twoValuesToggle"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    algolia:attribute="category"
    algolia:valueOn="book"
    algolia:valueOff="book"
    algolia:template="filtering {name} for {value}"/>

Common Parameters

attribute
type: string
Required

The faceted attribute that is refined by the toggle.

1
algolia:attribute="category"
template
type: string

Used as the Toggle’s text (if specified). Accepts the following templates:

  • {name}: the attribute name.
  • {value}: the refined value.
  • {isRefined} (only for OneValueToggle): true when refining, false otherwise.
1
algolia:template="filter {name} for {value}: {isRefined}"
autoHide
type: boolean
Optional

Whether the toggle should be hidden when there are no results.

1
algolia:autoHide="true"
variant
type: string

An identifier for the widget group this widget is part of. If specified, this widget is only linked to other widgets that have the same variant. See Multi-Index Searches.

1
algolia:variant="actors"

OneValueToggle

value
type: string
Required

The value to be applied when filtering the attribute.

1
algolia:value="book"

TwoValuesToggle

valueOn
type: string
Required

The value to be applied for attribute when the toggle is on.

1
algolia:valueOn="book"
valueOff
type: string
Required

The value to be applied for attribute when the toggle is off.

1
algolia:valueOff="magazine"

Did you find this page helpful?