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 |
abstract |
ViewHolder that supports |
Public constructors |
|
---|---|
<init>() Definition of items that can be inserted into |
Public methods |
|
---|---|
Unit |
addViewBinder(binder: ListItem.ViewBinder<VH>!) Same as |
Unit |
addViewBinder(binder: ListItem.ViewBinder<VH>!, @Nullable cleanUp: ListItem.ViewBinder<VH>?) Adds |
open Boolean |
Returns whether or not the divider that comes after this ListItem should be shown. |
abstract Int |
Classes that extends |
open Boolean |
removeViewBinder(binder: ListItem.ViewBinder<VH>!) Removes the first occurrence of the specified item. |
abstract Unit |
setEnabled(enabled: Boolean) Sets the enabled state of the bound |
open Unit |
setShowDivider(showDivider: Boolean) Whether to show the item divider coming after this |
Protected methods |
|
---|---|
open Boolean |
isDirty() |
open Unit |
Marks this item as not dirty. |
open Unit |
Marks this item as dirty so |
abstract Unit |
onBind(viewHolder: VH) Binds this ListItem to |
abstract Unit |
Does the work that moves the ListItem from dirty state to clean state, i. |
Public constructors
Public methods
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:
<code>TextListItem item = new TextListItem(context);
item.setTitle("title");
item.addViewBinder((viewHolder) -> {
viewHolder.getTitle().doFoobar();
}, (viewHolder) -> {
viewHolder.getTitle().revertFoobar();
});
</code>
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. |
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 . |
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. |
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. |
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.
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
.
Protected methods
isDirty
protected open fun isDirty(): Boolean
Return | |
---|---|
Boolean: true if next bind() should call resolveDirtyState() . |
markClean
protected open fun markClean(): Unit
Marks this item as not dirty. No need to call resolveDirtyState()
in next bind().
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.
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.
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 bind
s 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()
.