# ButtonGroupState

Artifact: [androidx.xr.glimmer:glimmer](https://developer.android.com/jetpack/androidx/releases/xr-glimmer) [View Source](https://cs.android.com/search?q=file:androidx/xr/glimmer/ButtonGroup.kt+class:androidx.xr.glimmer.ButtonGroupState) Added in [1.0.0-alpha22](https://developer.android.com/jetpack/androidx/releases/xr-glimmer#1.0.0-alpha22)


```
sealed interface ButtonGroupState : ScrollableState
```

<br />

*** ** * ** ***

A state object that allows querying and controlling the state of a `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/ButtonGroup.composable#ButtonGroup(androidx.compose.ui.Modifier,androidx.xr.glimmer.ButtonGroupState,androidx.compose.foundation.layout.Arrangement.Horizontal,androidx.compose.ui.Alignment.Vertical,androidx.compose.foundation.layout.PaddingValues,kotlin.Function0)` component.

## Summary

| ### Public companion properties |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/runtime/saveable/Saver<https://developer.android.com/reference/kotlin/androidx/xr/glimmer/ButtonGroupState, *>` | `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/ButtonGroupState#Saver()` The default `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/ButtonGroupState#Saver()` implementation for `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/ButtonGroupState`. |

| ### Public functions |
|---|---|
| `suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/ButtonGroupState#animateScrollToItem(kotlin.Int,androidx.compose.animation.core.FiniteAnimationSpec)( index: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, animationSpec: https://developer.android.com/reference/kotlin/androidx/compose/animation/core/FiniteAnimationSpec<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html> )` Scroll to the item at `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/ButtonGroupState#animateScrollToItem(kotlin.Int,androidx.compose.animation.core.FiniteAnimationSpec)` with the given `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/ButtonGroupState#animateScrollToItem(kotlin.Int,androidx.compose.animation.core.FiniteAnimationSpec)`. |
| `suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/ButtonGroupState#scrollToItem(kotlin.Int)(index: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Jump instantly to the item at `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/ButtonGroupState#scrollToItem(kotlin.Int)`. |

| ### Public properties |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/ButtonGroupState#currentItemIndex()` Index of the current child. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/ButtonGroupState#itemCount()` The number of items currently within the ButtonGroup. |

### Inherited functions

From [androidx.compose.foundation.gestures.ScrollableState](https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/ScrollableState) `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/ScrollableState#dispatchRawDelta(kotlin.Float)(delta: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)` `suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/ScrollableState#scroll(androidx.compose.foundation.MutatePriority,kotlin.coroutines.SuspendFunction1)(scrollPriority: https://developer.android.com/reference/kotlin/androidx/compose/foundation/MutatePriority, block: suspend https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/ScrollScope.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)`

### Inherited properties

From [androidx.compose.foundation.gestures.ScrollableState](https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/ScrollableState) `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/ScrollableState#canScrollBackward()` `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/ScrollableState#canScrollForward()` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/ScrollableState#isScrollInProgress()` `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/ScrollableState#lastScrolledBackward()` `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/ScrollableState#lastScrolledForward()` `open https://developer.android.com/reference/kotlin/androidx/compose/foundation/ScrollIndicatorState?` `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/ScrollableState#scrollIndicatorState()`

## Public companion properties

### Saver

Added in [1.0.0-alpha22](https://developer.android.com/jetpack/androidx/releases/xr-glimmer#1.0.0-alpha22)

```
val Saver: Saver<ButtonGroupState, *>
```

The default `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/ButtonGroupState#Saver()` implementation for `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/ButtonGroupState`.

## Public functions

### animateScrollToItem

Added in [1.0.0-alpha22](https://developer.android.com/jetpack/androidx/releases/xr-glimmer#1.0.0-alpha22)

```
suspend fun animateScrollToItem(
    index: Int,
    animationSpec: FiniteAnimationSpec<Float> = ButtonGroupDefaults.AnimateScrollToItemAnimationSpec
): Unit
```

Scroll to the item at `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/ButtonGroupState#animateScrollToItem(kotlin.Int,androidx.compose.animation.core.FiniteAnimationSpec)` with the given `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/ButtonGroupState#animateScrollToItem(kotlin.Int,androidx.compose.animation.core.FiniteAnimationSpec)`.

If the `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/ButtonGroup.composable#ButtonGroup(androidx.compose.ui.Modifier,androidx.xr.glimmer.ButtonGroupState,androidx.compose.foundation.layout.Arrangement.Horizontal,androidx.compose.ui.Alignment.Vertical,androidx.compose.foundation.layout.PaddingValues,kotlin.Function0)` has focus, focus will be requested for the child at this index.

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` | if `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/ButtonGroupState#animateScrollToItem(kotlin.Int,androidx.compose.animation.core.FiniteAnimationSpec)` is not in `[0, itemCount)` |

### scrollToItem

Added in [1.0.0-alpha22](https://developer.android.com/jetpack/androidx/releases/xr-glimmer#1.0.0-alpha22)

```
suspend fun scrollToItem(index: Int): Unit
```

Jump instantly to the item at `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/ButtonGroupState#scrollToItem(kotlin.Int)`.

If the `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/ButtonGroup.composable#ButtonGroup(androidx.compose.ui.Modifier,androidx.xr.glimmer.ButtonGroupState,androidx.compose.foundation.layout.Arrangement.Horizontal,androidx.compose.ui.Alignment.Vertical,androidx.compose.foundation.layout.PaddingValues,kotlin.Function0)` has focus, focus will be requested for the child at this index.

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` | if `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/ButtonGroupState#scrollToItem(kotlin.Int)` is not in `[0, itemCount)` |

## Public properties

### currentItemIndex

Added in [1.0.0-alpha22](https://developer.android.com/jetpack/androidx/releases/xr-glimmer#1.0.0-alpha22)

```
val currentItemIndex: Int
```

Index of the current child.

The index updates continuously as the user scrolls. To get updates only when the index is "settled", use the current item index when `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/ScrollableState#isScrollInProgress()` is `false`.

Returns -1 if the `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/ButtonGroup.composable#ButtonGroup(androidx.compose.ui.Modifier,androidx.xr.glimmer.ButtonGroupState,androidx.compose.foundation.layout.Arrangement.Horizontal,androidx.compose.ui.Alignment.Vertical,androidx.compose.foundation.layout.PaddingValues,kotlin.Function0)` is empty, or if the layout has not been initialized yet.

### itemCount

Added in [1.0.0-alpha22](https://developer.android.com/jetpack/androidx/releases/xr-glimmer#1.0.0-alpha22)

```
val itemCount: Int
```

The number of items currently within the ButtonGroup.