lightbulb_outline Please take our October 2018 developer survey. Start survey

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

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.

boolean getShowDivider()

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

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.

abstract void setEnabled(boolean enabled)

Sets the enabled state of the bound ListItem.ViewHolder.

void setHideDivider(boolean hideDivider)

This method is deprecated. Use setShowDivider(boolean).

void setShowDivider(boolean showDivider)

Whether to show the item divider coming after this ListItem.

boolean shouldHideDivider()

This method is deprecated. Use getShowDivider().

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

public ListItem ()

Public methods

addViewBinder

public final 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

public final void addViewBinder (ViewBinder<VH> binder)

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

Parameters
binder ViewBinder: to interact with subviews in ViewHolder.

getShowDivider

public boolean getShowDivider ()

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

Returns
boolean true if the divider should be shown. Defaults to true.

getViewType

public abstract int getViewType ()

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

Returns
int type of this ListItem.

removeViewBinder

public 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.

setEnabled

public abstract void setEnabled (boolean enabled)

Sets the enabled state of the bound ListItem.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.

Parameters
enabled boolean

setHideDivider

public void setHideDivider (boolean hideDivider)

This method is deprecated.
Use setShowDivider(boolean).

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

setShowDivider

public void setShowDivider (boolean showDivider)

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.

Parameters
showDivider boolean

shouldHideDivider

public boolean shouldHideDivider ()

This method is deprecated.
Use getShowDivider().

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

Protected methods

isDirty

protected boolean isDirty ()

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

markClean

protected void markClean ()

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

markDirty

protected void markDirty ()

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

This method should be called in each setter.

onBind

protected abstract 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

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