# RowSection.Builder

Artifact: [androidx.car.app:app](https://developer.android.com/jetpack/androidx/releases/car-app) [View Source](https://cs.android.com/search?q=file:androidx/car/app/model/RowSection.java+class:androidx.car.app.model.RowSection.Builder) Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.7.0)

*** ** * ** ***


```
public final class RowSection.Builder extends Section.BaseBuilder<Row, RowSection.Builder>
```

<br />

|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.html) |||
| ↳ | [androidx.car.app.model.Section.BaseBuilder](https://developer.android.com/reference/androidx/car/app/model/Section.BaseBuilder)\<[Row](https://developer.android.com/reference/androidx/car/app/model/Row), [RowSection.Builder](https://developer.android.com/reference/androidx/car/app/model/RowSection.Builder)\> ||
|   | ↳ | [androidx.car.app.model.RowSection.Builder](https://developer.android.com/reference/androidx/car/app/model/RowSection.Builder) |

*** ** * ** ***

A builder that constructs `https://developer.android.com/reference/androidx/car/app/model/RowSection` instances.

Upon building, this class validates the following:

- If this section is set as a selection group, the given `initialSelectedIndex` cannot be greater than the size of the list (unless the list is empty, in which case this value is ignored)
- If this section is set as a selection group, none of the added `https://developer.android.com/reference/androidx/car/app/model/Row`s can have a `https://developer.android.com/reference/androidx/car/app/model/Row.Builder#setToggle(androidx.car.app.model.Toggle)` set
- Each `https://developer.android.com/reference/androidx/car/app/model/Row` must conform to

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/car/app/model/RowSection.Builder#Builder()()` Create a new `https://developer.android.com/reference/androidx/car/app/model/RowSection` builder. |

| ### Public methods |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/RowSection` | `https://developer.android.com/reference/androidx/car/app/model/RowSection.Builder#build()()` Constructs a new `https://developer.android.com/reference/androidx/car/app/model/RowSection` from the current state of this builder, throwing exceptions for any invalid state. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/RowSection.Builder` | `@https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html https://developer.android.com/reference/androidx/car/app/model/RowSection.Builder#clearSelectionGroup()()` Unsets this `https://developer.android.com/reference/androidx/car/app/model/RowSection` from being shown as a selection group. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/RowSection.Builder` | `@https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html https://developer.android.com/reference/androidx/car/app/model/RowSection.Builder#setAsSelectionGroup(int)(int initialSelectedIndex)` Sets this entire `https://developer.android.com/reference/androidx/car/app/model/RowSection` as a selection group when passed a non-negative integer correlating to a valid index within the list of items added. |

### Inherited methods

From [androidx.car.app.model.Section.BaseBuilder](https://developer.android.com/reference/androidx/car/app/model/Section.BaseBuilder) `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html B` `@https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html
https://developer.android.com/reference/androidx/car/app/model/Section.BaseBuilder#addItem(T)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html T item)`

Adds an item to this section, appending to the existing list of items.
`@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html B` `@https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html
https://developer.android.com/reference/androidx/car/app/model/Section.BaseBuilder#clearItems()()`

Delete all items in this section.
`@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html B` `@https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html
https://developer.android.com/reference/androidx/car/app/model/Section.BaseBuilder#setItems(java.util.List<T>)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/List.html<T> items)`

Sets the items for this section, overwriting any other previously set items.
`@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html B` `@https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html
https://developer.android.com/reference/androidx/car/app/model/Section.BaseBuilder#setNoItemsMessage(androidx.car.app.model.CarText)(@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/car/app/model/CarText noItemsMessage)`

Sets or clears the optional message to display in this section when there are 0 items added to it.
`@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html B` `@https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html
https://developer.android.com/reference/androidx/car/app/model/Section.BaseBuilder#setNoItemsMessage(java.lang.CharSequence)(@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/CharSequence.html noItemsMessage)`

Sets or clears the optional message to display in this section when there are 0 items added to it.
`@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html B` `@https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html
https://developer.android.com/reference/androidx/car/app/model/Section.BaseBuilder#setOnItemVisibilityChangedListener(androidx.car.app.model.ItemList.OnItemVisibilityChangedListener)(
@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/car/app/model/ItemList.OnItemVisibilityChangedListener onItemVisibilityChangedListener
)`

Sets the `https://developer.android.com/reference/androidx/car/app/model/ItemList.OnItemVisibilityChangedListener` to call when the visible items in this `https://developer.android.com/reference/androidx/car/app/model/Section` changes.
`@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html B` `@https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html
@https://developer.android.com/reference/androidx/car/app/annotations/RequiresCarApi(value = 9)
@https://developer.android.com/reference/androidx/car/app/annotations/ExperimentalCarApi
https://developer.android.com/reference/androidx/car/app/model/Section.BaseBuilder#setSectionHeader(androidx.car.app.model.SectionHeader)(@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/car/app/model/SectionHeader sectionHeader)`

Sets the `https://developer.android.com/reference/androidx/car/app/model/SectionHeader` for this section.
`@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html B` `@https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html
https://developer.android.com/reference/androidx/car/app/model/Section.BaseBuilder#setTitle(androidx.car.app.model.CarText)(@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/car/app/model/CarText title)`

Sets or clears the optional title that appears above the items in this section.
`@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html B` `@https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html
https://developer.android.com/reference/androidx/car/app/model/Section.BaseBuilder#setTitle(java.lang.CharSequence)(@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/CharSequence.html title)`

Sets or clears the optional title that appears above the items in this section.

## Public constructors

### Builder

Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.7.0)

```
public Builder()
```

Create a new `https://developer.android.com/reference/androidx/car/app/model/RowSection` builder.

## Public methods

### build

Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.7.0)

```
public @NonNull RowSection build()
```

Constructs a new `https://developer.android.com/reference/androidx/car/app/model/RowSection` from the current state of this builder, throwing exceptions for any invalid state.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/car/app/model/RowSection.Builder` | for the list of validation logic |

### clearSelectionGroup

Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.7.0)

```
@CanIgnoreReturnValue
public @NonNull RowSection.Builder clearSelectionGroup()
```

Unsets this `https://developer.android.com/reference/androidx/car/app/model/RowSection` from being shown as a selection group. See `https://developer.android.com/reference/androidx/car/app/model/RowSection.Builder#setAsSelectionGroup(int)`.

### setAsSelectionGroup

Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.7.0)

```
@CanIgnoreReturnValue
public @NonNull RowSection.Builder setAsSelectionGroup(int initialSelectedIndex)
```

Sets this entire `https://developer.android.com/reference/androidx/car/app/model/RowSection` as a selection group when passed a non-negative integer correlating to a valid index within the list of items added. The UI behaves equivalently to a radio button group where a single item is called out (either by an actual radio button, or through some other highlighting). The host will initially highlight the `initialSelectedIndex`'s item and automatically update the highlight to other items if selected by the user. The app should handle user selections via `https://developer.android.com/reference/androidx/car/app/model/Row.Builder#setOnClickListener(androidx.car.app.model.OnClickListener)`.

This cannot be used in conjunction with `https://developer.android.com/reference/androidx/car/app/model/Row.Builder#setToggle(androidx.car.app.model.Toggle)`.

| Parameters |
|---|---|
| `int initialSelectedIndex` | the index of the item to be selected when the template is first rendered |