Android 12 Developer Preview is here! Try it out, and give us your feedback!

ListTemplate.Builder

public static final class ListTemplate.Builder
extends Object

java.lang.Object
   ↳ com.google.android.libraries.car.app.model.ListTemplate.Builder


A builder of ListTemplate.

Summary

Public methods

ListTemplate.Builder addList(ItemList list, CharSequence header)

Adds an ItemList to display in the template.

ListTemplate build()

Constructs the template defined by this builder.

ListTemplate.Builder clearAllLists()

Resets any list(s) that were added via setSingleList(ItemList) or addList(ItemList, CharSequence).

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 setIsLoading(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 CharSequence to show as the template's title, or null to not show a title.

Inherited methods

Public methods

addList

public ListTemplate.Builder addList (ItemList list, 
                CharSequence header)

Adds an ItemList to display in the template.

Use this method to add multiple ItemLists to the template. Each ItemList will be grouped under the given 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 ItemList contains a ItemList.OnSelectedListener, then it cannot be added alongside other ItemList(s).

Parameters
list ItemList

header CharSequence

Returns
ListTemplate.Builder

Throws
NullPointerException if list is null.
IllegalArgumentException if list is empty.
IllegalArgumentException if list's ItemList.OnItemVisibilityChangedListener is set.
NullPointerException if header is null.
IllegalArgumentException if header is empty.
IllegalArgumentException 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(CharSequence).

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.
IllegalArgumentException if the added ItemList(s) do not meet the template's requirements.
IllegalStateException if the template does not have either a title or header Action set.

clearAllLists

public ListTemplate.Builder clearAllLists ()

Resets any list(s) that were added via setSingleList(ItemList) or addList(ItemList, CharSequence).

Returns
ListTemplate.Builder

setActionStrip

public ListTemplate.Builder setActionStrip (ActionStrip actionStrip)

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

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(CharSequence). Otherwise, only Actions with icons are allowed.

Parameters
actionStrip ActionStrip

Returns
ListTemplate.Builder

Throws
IllegalArgumentException if actionStrip does not meet the requirements.

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.

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.

setIsLoading

public ListTemplate.Builder setIsLoading (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 addList(ItemList, CharSequence).

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 addList(ItemList, CharSequence). 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 CharSequence to show as the template's title, or null to not show a title.

Parameters
title CharSequence

Returns
ListTemplate.Builder