ItemList.Builder
public
static
class
ItemList.Builder
extends Object
java.lang.Object | |
↳ | com.google.android.libraries.car.app.model.ItemList.Builder |
A builder of ItemList
.
Summary
Public constructors | |
---|---|
Builder()
|
Public methods | |
---|---|
ItemList.Builder
|
addItem(Item item)
Adds an item to the list. |
ItemList
|
build()
Constructs the item list defined by this builder. |
ItemList.Builder
|
clearItems()
Clears any items that may have been added up to this point. |
ItemList.Builder
|
setNoItemsMessage(CharSequence noItemsMessage)
Sets the text to display if the list is empty. |
ItemList.Builder
|
setOnItemsVisibilityChangeListener(ItemList.OnItemVisibilityChangedListener itemVisibilityChangedListener)
Sets the |
ItemList.Builder
|
setSelectable(ItemList.OnSelectedListener onSelectedListener)
Marks the list as selectable and sets the |
ItemList.Builder
|
setSelectedIndex(int selectedIndex)
Sets the index of the item to show as selected. |
Inherited methods | |
---|---|
Public constructors
Builder
public Builder ()
Public methods
addItem
public ItemList.Builder addItem (Item item)
Adds an item to the list.
Parameters | |
---|---|
item |
Item |
Returns | |
---|---|
ItemList.Builder |
Throws | |
---|---|
NullPointerException |
if item is null .
|
build
public ItemList build ()
Constructs the item list defined by this builder.
Returns | |
---|---|
ItemList |
Throws | |
---|---|
IllegalStateException |
if the list is selectable but does not have any items. |
IllegalStateException |
if the selected index is greater or equal to the size of the list. |
IllegalStateException |
if the list is selectable and any items have either one of
their OnClickListener or Toggle set.
|
clearItems
public ItemList.Builder clearItems ()
Clears any items that may have been added up to this point.
Returns | |
---|---|
ItemList.Builder |
setNoItemsMessage
public ItemList.Builder setNoItemsMessage (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.
Parameters | |
---|---|
noItemsMessage |
CharSequence |
Returns | |
---|---|
ItemList.Builder |
setOnItemsVisibilityChangeListener
public ItemList.Builder setOnItemsVisibilityChangeListener (ItemList.OnItemVisibilityChangedListener itemVisibilityChangedListener)
Sets the ItemList.OnItemVisibilityChangedListener
to call when the visible items in the list
changes.
Parameters | |
---|---|
itemVisibilityChangedListener |
ItemList.OnItemVisibilityChangedListener |
Returns | |
---|---|
ItemList.Builder |
setSelectable
public ItemList.Builder setSelectable (ItemList.OnSelectedListener onSelectedListener)
Marks the list as selectable and sets the ItemList.OnSelectedListener
to call when an item is
selected by the user. 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.
Parameters | |
---|---|
onSelectedListener |
ItemList.OnSelectedListener |
Returns | |
---|---|
ItemList.Builder |
See also:
setSelectedIndex
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 setSelectable(ItemList.OnSelectedListener)
, this value is
ignored.
Parameters | |
---|---|
selectedIndex |
int |
Returns | |
---|---|
ItemList.Builder |