ListItem

abstract class ListItem<VH : ListItem.ViewHolder!>
kotlin.Any
   ↳ androidx.car.widget.ListItem

Definition of items that can be inserted into ListItemAdapter.

Summary

Nested classes
abstract

Functional interface to provide a way to interact with views in ViewHolder.

abstract

ViewHolder that supports ViewBinder.

Public constructors

Definition of items that can be inserted into ListItemAdapter.

Public methods
open Boolean

open Boolean

Removes the first occurrence of the specified item.

open Unit
setShowDivider(showDivider: Boolean)

Whether to show the item divider coming after this ListItem.

Unit

Same as addViewBinder(ViewBinder, ViewBinder) when cleanUp ViewBinder is null.

Unit
addViewBinder(binder: ListItem.ViewBinder<VH>!, @Nullable cleanUp: ListItem.ViewBinder<VH>?)

Adds ViewBinder to interact with sub-views in ViewHolder.

abstract Unit
setEnabled(enabled: Boolean)

Sets the enabled state of the bound ViewHolder.

abstract Int

Classes that extends ListItem should register its view type in ListItemAdapter#registerListItemViewType(int, int, Function).

open Boolean

Returns whether or not the divider that comes after this ListItem should be shown.

open Unit
setHideDivider(hideDivider: Boolean)

Whether hide the item divider coming after this ListItem.

Protected methods
open Unit

Marks this item as dirty so resolveDirtyState() is required in next bind() call.

abstract Unit

Does the work that moves the ListItem from dirty state to clean state, i.

open Unit

Marks this item as not dirty.

open Boolean

abstract Unit
onBind(viewHolder: VH)

Binds this ListItem to viewHolder by applying data in ListItem to sub-views.

Public constructors

<init>

ListItem()

Definition of items that can be inserted into ListItemAdapter.

Public methods

shouldHideDivider

open fun shouldHideDivider(): Boolean
Return
Boolean: true if the divider that comes after this ListItem should be hidden. Defaults to false.

removeViewBinder

open fun removeViewBinder(binder: ListItem.ViewBinder<VH>!): Boolean

Removes the first occurrence of the specified item.

Parameters
binder ListItem.ViewBinder<VH>!: to be removed.
Return
Boolean: true if binder exists. false otherwise.

setShowDivider

open fun setShowDivider(showDivider: Boolean): Unit

Whether to show the item divider coming after this ListItem.

Note: For this to work, one must invoke PagedListView.setDividerVisibilityManager(adapter for ListItemAdapter and have dividers enabled on PagedListView.

addViewBinder

fun addViewBinder(binder: ListItem.ViewBinder<VH>!): Unit

Same as addViewBinder(ViewBinder, ViewBinder) when cleanUp ViewBinder is null.

Parameters
binder ListItem.ViewBinder<VH>!: to interact with subviews in ViewHolder.

addViewBinder

fun addViewBinder(binder: ListItem.ViewBinder<VH>!, @Nullable cleanUp: ListItem.ViewBinder<VH>?): Unit

Adds ViewBinder to interact with sub-views in ViewHolder. These ViewBinders will always be applied after onBind(ViewHolder).

To interact with a foobar sub-view in ViewHolder, make sure to first set its visibility, or call setFoobar() setter method.

Example:

 TextListItem item = new TextListItem(context); item.setTitle("title"); item.addViewBinder((viewHolder) -> { viewHolder.getTitle().doFoobar(); }, (viewHolder) -> { viewHolder.getTitle().revertFoobar(); });  
Parameters
binder ListItem.ViewBinder<VH>!: to interact with subviews in ViewHolder.
cleanUp ListItem.ViewBinder<VH>!: view binder to revert the effect of binder. cleanUp binders will be stored in ListItem.ViewHolder and should be invoked via ViewHolder#cleanUp() before ViewHolder is recycled. This is to avoid changed made to ViewHolder lingers around when ViewHolder is recycled. Pass in null to skip.

setEnabled

abstract fun setEnabled(enabled: Boolean): Unit

Sets the enabled state of the bound ViewHolder.

All visible children views of ViewHolder should be set to enabled. Caller is responsible for notifying ListItemAdapter about data change.

Disabled items are usually styled at 50% opacity. Consider similar styling for consistency.

getViewType

abstract fun getViewType(): Int

Classes that extends ListItem should register its view type in ListItemAdapter#registerListItemViewType(int, int, Function).

Return
Int: type of this ListItem.

getShowDivider

open fun getShowDivider(): Boolean

Returns whether or not the divider that comes after this ListItem should be shown.

Return
Boolean: true if the divider should be shown. Defaults to true.

setHideDivider

open fun setHideDivider(hideDivider: Boolean): Unit

Whether hide the item divider coming after this ListItem.

Note: For this to work, one must invoke PagedListView.setDividerVisibilityManager(adapter for ListItemAdapter and have dividers enabled on PagedListView.

Protected methods

markDirty

protected open fun markDirty(): Unit

Marks this item as dirty so resolveDirtyState() is required in next bind() call.

This method should be called in each setter.

resolveDirtyState

protected abstract fun resolveDirtyState(): Unit

Does the work that moves the ListItem from dirty state to clean state, i.e. the work required the first time this ListItem binds to ListItem.ViewHolder. This method will transition ListItem to clean state. ListItem in clean state should move to dirty state when it is modified by calling markDirty().

markClean

protected open fun markClean(): Unit

Marks this item as not dirty. No need to call resolveDirtyState() in next bind().

isDirty

protected open fun isDirty(): Boolean
Return
Boolean: true if next bind() should call resolveDirtyState().

onBind

protected abstract fun onBind(viewHolder: VH): Unit

Binds this ListItem to viewHolder by applying data in ListItem to sub-views. Assume ViewHolder#cleanUp() has already been invoked.