ItemList.Builder

class ItemList.Builder


A builder of ItemList.

Summary

Public constructors

Returns an empty Builder instance.

Public functions

ItemList.Builder
addItem(item: Item)

Adds an item to the list.

ItemList

Constructs the item list defined by this builder.

ItemList.Builder

Removes all Items added via addItem

ItemList.Builder

Sets the text to display if the list is empty.

ItemList.Builder

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

ItemList.Builder

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

ItemList.Builder
setSelectedIndex(selectedIndex: @IntRange(from = 0) Int)

Sets the index of the item to show as selected.

Public constructors

Builder

Added in 1.0.0
Builder()

Returns an empty Builder instance.

Public functions

addItem

Added in 1.0.0
fun addItem(item: Item): ItemList.Builder

Adds an item to the list.

Throws
java.lang.NullPointerException

if item is null

build

Added in 1.0.0
fun build(): ItemList

Constructs the item list defined by this builder.

Throws
java.lang.IllegalStateException

if the list is selectable but does not have any items, if the selected index is greater or equal to the size of the list, or if the list is selectable and any items have either one of their OnClickListener or Toggle set

clearItems

Added in 1.3.0
@ExperimentalCarApi
fun clearItems(): ItemList.Builder

Removes all Items added via addItem

setNoItemsMessage

Added in 1.0.0
fun setNoItemsMessage(noItemsMessage: CharSequence): ItemList.Builder

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.

Throws
java.lang.NullPointerException

if noItemsMessage is null

setOnItemsVisibilityChangedListener

Added in 1.0.0
fun setOnItemsVisibilityChangedListener(
    itemVisibilityChangedListener: ItemList.OnItemVisibilityChangedListener
): ItemList.Builder

Sets the 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 getMainLooper.

Throws
java.lang.NullPointerException

if itemVisibilityChangedListener is null

setOnSelectedListener

Added in 1.0.0
fun setOnSelectedListener(onSelectedListener: ItemList.OnSelectedListener): ItemList.Builder

Marks the list as selectable by setting the 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.

Throws
java.lang.NullPointerException

if onSelectedListener is null

See also
setSelectedIndex

setSelectedIndex

Added in 1.0.0
fun setSelectedIndex(selectedIndex: @IntRange(from = 0) Int): ItemList.Builder

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 setOnSelectedListener, this value is ignored.