public final class

ItemList.Builder

extends java.lang.Object

 java.lang.Object

↳androidx.car.app.model.ItemList.Builder

Overview

A builder of ItemList.

Summary

Constructors
publicBuilder()

Returns an empty ItemList.Builder instance.

Methods
public ItemList.BuilderaddItem(Item item)

Adds an item to the list.

public ItemListbuild()

Constructs the item list defined by this builder.

public ItemList.BuildersetNoItemsMessage(java.lang.CharSequence noItemsMessage)

Sets the text to display if the list is empty.

public ItemList.BuildersetOnItemsVisibilityChangedListener(ItemList.OnItemVisibilityChangedListener itemVisibilityChangedListener)

Sets the ItemList.OnItemVisibilityChangedListener to call when the visible items in the list changes.

public ItemList.BuildersetOnSelectedListener(ItemList.OnSelectedListener onSelectedListener)

Marks the list as selectable by setting the ItemList.OnSelectedListener to call when an item is selected by the user, or set to null to mark the list as non-selectable.

public ItemList.BuildersetSelectedIndex(int selectedIndex)

Sets the index of the item to show as selected.

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public Builder()

Returns an empty ItemList.Builder instance.

Methods

public ItemList.Builder setOnItemsVisibilityChangedListener(ItemList.OnItemVisibilityChangedListener itemVisibilityChangedListener)

Sets the ItemList.OnItemVisibilityChangedListener to call when the visible items in the list changes.

Note that the listener relates to UI events and will be executed on the main thread using .

public ItemList.Builder setOnSelectedListener(ItemList.OnSelectedListener onSelectedListener)

Marks the list as selectable by setting the ItemList.OnSelectedListener to call when an item is selected by the user, or set to null to mark the list as non-selectable.

Selectable lists, where allowed by the template they are added to, automatically display an item in a selected state when selected by the user.

The items in the list define a mutually exclusive selection scope: only a single item will be selected at any given time.

The specific way in which the selection will be visualized depends on the template and the host implementation. For example, some templates may display the list as a radio button group, while others may highlight the selected item's background.

See also: ItemList.Builder.setSelectedIndex(int)

public ItemList.Builder setSelectedIndex(int selectedIndex)

Sets the index of the item to show as selected.

By default and unless explicitly set with this method, the first item is selected.

If the list is not a selectable list set with ItemList.Builder.setOnSelectedListener(ItemList.OnSelectedListener), this value is ignored.

public ItemList.Builder setNoItemsMessage(java.lang.CharSequence noItemsMessage)

Sets the text to display if the list is empty.

If the list is empty and the app does not explicitly set the message with this method, the host will show a default message.

Spans are not supported in the input string and will be ignored.

public ItemList.Builder addItem(Item item)

Adds an item to the list.

public ItemList build()

Constructs the item list defined by this builder.