ListTemplate.Builder

public static final class ListTemplate.Builder
extends Object

java.lang.Object
   ↳ androidx.car.app.model.ListTemplate.Builder


A builder of ListTemplate.

Summary

Public constructors

Builder()

Returns an empty ListTemplate.Builder instance.

Public methods

ListTemplate.Builder addSectionedList(SectionedItemList list)

Adds an SectionedItemList to display in the template.

ListTemplate build()

Constructs the template defined by this builder.

ListTemplate.Builder setActionStrip(ActionStrip actionStrip)

Sets the ActionStrip for this template or null to not display an ActionStrip.

ListTemplate.Builder setHeaderAction(Action headerAction)

Sets the Action that will be displayed in the header of the template, or null to not display an action.

ListTemplate.Builder setLoading(boolean isLoading)

Sets whether the template is in a loading state.

ListTemplate.Builder setSingleList(ItemList list)

Sets a single ItemList to show in the template.

ListTemplate.Builder setTitle(CharSequence title)

Sets the title of the template.

Inherited methods

Public constructors

Builder

public Builder ()

Returns an empty ListTemplate.Builder instance.

Public methods

addSectionedList

public ListTemplate.Builder addSectionedList (SectionedItemList list)

Adds an SectionedItemList to display in the template.

Use this method to add multiple lists to the template. Each SectionedItemList will be grouped under its header. These lists cannot be mixed with an ItemList added via setSingleList(ItemList). If a single list was previously added, it will be cleared.

If the added SectionedItemList contains a ItemList.OnSelectedListener, then it cannot be added alongside other SectionedItemList(s).

Parameters
list SectionedItemList

Returns
ListTemplate.Builder

Throws
NullPointerException if list or header is null
IllegalArgumentException if list is empty, if list's ItemList.OnItemVisibilityChangedListener is set, if header is empty, or if a selectable list is added alongside other lists

build

public ListTemplate build ()

Constructs the template defined by this builder.

Requirements

The number of items in the ItemList should be smaller or equal than the limit provided by ConstraintManager.CONTENT_LIMIT_TYPE_LIST. The host will ignore any items over that limit. Each Rows can add up to 2 lines of texts via Row.Builder.addText(CarText).

Either a header Action or the title must be set on the template.

Returns
ListTemplate

Throws
IllegalStateException if the template is in a loading state but there are lists added or vice versa, or if the template does not have either a title or header Action set
IllegalArgumentException if the added ItemList(s) do not meet the template's requirements

setActionStrip

public ListTemplate.Builder setActionStrip (ActionStrip actionStrip)

Sets the ActionStrip for this template or null to not display an ActionStrip.

Unless set with this method, the template will not have an action strip.

Requirements

This template allows up to 2 Actions in its ActionStrip. Of the 2 allowed Actions, one of them can contain a title as set via Action.Builder.setTitle(CarText). Otherwise, only Actions with icons are allowed.

Parameters
actionStrip ActionStrip

Returns
ListTemplate.Builder

Throws
IllegalArgumentException