belongs to Maven artifact androidx.car:car:1.0.0-alpha1

ListItem

public abstract class ListItem
extends Object

java.lang.Object
   ↳ androidx.car.widget.ListItem<VH extends androidx.car.widget.ListItem.ViewHolder>


Definition of items that can be inserted into ListItemAdapter.

Summary

Nested classes

interface ListItem.ViewBinder<VH>

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

class ListItem.ViewHolder

ViewHolder that supports ListItem.ViewBinder

Public constructors

ListItem()

Public methods

final void addViewBinder(ViewBinder<VH> binder, ViewBinder<VH> cleanUp)

Adds ListItem.ViewBinder to interact with sub-views in ListItem.ViewHolder.

final void addViewBinder(ViewBinder<VH> binder)

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

abstract int getViewType()

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

boolean removeViewBinder(ViewBinder<VH> binder)

Removes the first occurrence of the specified item.

void setHideDivider(boolean hideDivider)

Whether hide the item divider coming after this ListItem.

boolean shouldHideDivider()

Protected methods

boolean isDirty()
void markClean()

Marks this item as not dirty.

void markDirty()

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

abstract void onBind(VH viewHolder)

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

abstract void resolveDirtyState()

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

Inherited methods

Public constructors

ListItem

ListItem ()

Public methods

addViewBinder

void addViewBinder (ViewBinder<VH> binder, 
                ViewBinder<VH> cleanUp)

Adds ListItem.ViewBinder to interact with sub-views in ListItem.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 ViewBinder: to interact with subviews in ViewHolder.

cleanUp ViewBinder: view binder to revert the effect of binder. cleanUp binders will be stored in ListItem.ViewHolder and should be invoked via ListItem.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.

addViewBinder

void addViewBinder (ViewBinder<VH> binder)

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

Parameters
binder ViewBinder: to interact with subviews in ViewHolder.

getViewType

int getViewType ()

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

Returns
int type of this ListItem.

removeViewBinder

boolean removeViewBinder (ViewBinder<VH> binder)

Removes the first occurrence of the specified item.

Parameters
binder ViewBinder: to be removed.

Returns
boolean true if binder exists. false otherwise.

setHideDivider

void setHideDivider (boolean hideDivider)

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.

Parameters
hideDivider boolean

shouldHideDivider

boolean shouldHideDivider ()

Returns
boolean true if the divider that comes after this ListItem should be hidden. Defaults to false.

Protected methods

isDirty

boolean isDirty ()

Returns
boolean true if next bind() should call resolveDirtyState().

markClean

void markClean ()

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

markDirty

void markDirty ()

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

This method should be called in each setter.

onBind

void onBind (VH viewHolder)

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

Parameters
viewHolder VH

resolveDirtyState

void resolveDirtyState ()

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().