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

This template allows up to 6 Rows total in the ItemList(s). 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 if actionStrip does not meet the requirements
NullPointerException if actionStrip is null

setHeaderAction

public 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.

Unless set with this method, the template will not have a header action.

Requirements

This template only supports either one of Action.APP_ICON and Action.BACK as a header Action.

Parameters
headerAction Action

Returns
ListTemplate.Builder

Throws
IllegalArgumentException if headerAction does not meet the template's requirements
NullPointerException if headerAction is null

setLoading

public ListTemplate.Builder setLoading (boolean isLoading)

Sets whether the template is in a loading state.

If set to true, the UI will display a loading indicator where the list content would be otherwise. The caller is expected to call Screen.invalidate() and send the new template content to the host once the data is ready.

If set to false, the UI will display the contents of the ItemList instance(s) added via setSingleList(ItemList) or addSectionedList(SectionedItemList).

Parameters
isLoading boolean

Returns
ListTemplate.Builder

setSingleList

public ListTemplate.Builder setSingleList (ItemList list)

Sets a single ItemList to show in the template.

Note that this list cannot be mixed with others added via addSectionedList(SectionedItemList) . If multiple lists were previously added, they will be cleared.

Parameters
list ItemList

Returns
ListTemplate.Builder

Throws
NullPointerException if list is null

setTitle

public ListTemplate.Builder setTitle (CharSequence title)

Sets the title of the template.

Unless set with this method, the template will not have a title.

Spans are not supported in the input string.

Parameters
title CharSequence

Returns
ListTemplate.Builder

Throws
NullPointerException if title is null