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 |
class |
ListItem.ViewHolder
ViewHolder that supports |
Public constructors | |
|---|---|
ListItem()
|
|
Public methods | |
|---|---|
final
void
|
addViewBinder(ViewBinder<VH> binder, ViewBinder<VH> cleanUp)
Adds |
final
void
|
addViewBinder(ViewBinder<VH> binder)
Same as |
boolean
|
getShowDivider()
Returns whether or not the divider that comes after this ListItem should be shown. |
abstract
int
|
getViewType()
Classes that extends |
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 |
void
|
setShowDivider(boolean showDivider)
Whether to show the item divider coming after this |
Protected methods | |
|---|---|
boolean
|
isDirty()
|
void
|
markClean()
Marks this item as not dirty. |
void
|
markDirty()
Marks this item as dirty so |
abstract
void
|
onBind(VH viewHolder)
Binds this ListItem to |
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. |
See also:
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 |
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 |
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().
Content and code samples on this page are subject to the licenses described in the Content License. Java is a registered trademark of Oracle and/or its affiliates.