RowSection.Builder


@ExperimentalCarApi
public final class RowSection.Builder extends Section.BaseBuilder


A builder that constructs 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 Rows can have a setToggle set
  • Each Row must conform to ROW_CONSTRAINTS_FULL_LIST

Summary

Public constructors

Create a new RowSection builder.

Public methods

@NonNull RowSection

Constructs a new RowSection from the current state of this builder, throwing exceptions for any invalid state.

@NonNull RowSection.Builder

Unsets this RowSection from being shown as a selection group.

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

Sets this entire 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
@NonNull B

Adds an item to this section, appending to the existing list of items.

@NonNull B

Delete all items in this section.

@NonNull B

Sets the items for this section, overwriting any other previously set items.

@NonNull B

Sets or clears the optional message to display in this section when there are 0 items added to it.

@NonNull B

Sets or clears the optional message to display in this section when there are 0 items added to it.

@NonNull B

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

@NonNull B

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

Public constructors

Builder

Added in 1.7.0-beta02
public Builder()

Create a new RowSection builder.

Public methods

build

Added in 1.7.0-beta02
public @NonNull RowSection build()

Constructs a new RowSection from the current state of this builder, throwing exceptions for any invalid state.

See also
RowSection.Builder

for the list of validation logic

clearSelectionGroup

Added in 1.7.0-beta02
@CanIgnoreReturnValue
public @NonNull RowSection.Builder clearSelectionGroup()

Unsets this RowSection from being shown as a selection group. See setAsSelectionGroup.

setAsSelectionGroup

Added in 1.7.0-beta02
@CanIgnoreReturnValue
public @NonNull RowSection.Builder setAsSelectionGroup(int initialSelectedIndex)

Sets this entire 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 setOnClickListener.

This cannot be used in conjunction with setToggle.

Parameters
int initialSelectedIndex

the index of the item to be selected when the template is first rendered