Save the date! Android Dev Summit is coming to Sunnyvale, CA on Oct 23-24, 2019.

ListItemAdapter

open class ListItemAdapter : RecyclerView.Adapter<ListItem.ViewHolder!>, PagedListView.ItemCap, PagedListView.DividerVisibilityManager
kotlin.Any
   ↳ androidx.recyclerview.widget.RecyclerView.Adapter<androidx.car.widget.ListItem.ViewHolder>
   ↳ androidx.car.widget.ListItemAdapter

Adapter for PagedListView to display ListItem.

To enable support for CarUxRestrictions, call start() in your Activity's android.app.Activity#onCreate(Bundle), and stop() in Activity#onStop().

Summary

Nested classes

Constant class for background style of items.

Inherited constants
Public constructors
<init>(@NonNull context: Context, @NonNull itemProvider: ListItemProvider<ListItem.ViewHolder!>)

Defaults BackgroundStyle to BackgroundStyle#NONE.

<init>(@NonNull context: Context, @NonNull itemProvider: ListItemProvider<ListItem.ViewHolder!>, backgroundStyle: Int)

Public methods
open Unit
registerListItemViewType(viewType: Int, @LayoutRes layoutResId: Int, function: Function<View!, ListItem.ViewHolder!>!)

Registers a custom ListItem that this adapter will handle.

open Unit
setMaxItems(maxItems: Int)

open ListItem.ViewHolder
onCreateViewHolder(parent: ViewGroup, viewType: Int)

open Int

open Unit

Enables support for CarUxRestrictions.

open Unit

open Int
getItemViewType(position: Int)

open Unit

open Context

open Unit

Disables support for CarUxRestrictions, and frees up resources.

open Boolean
getShowDivider(position: Int)

Inherited functions

Public constructors

<init>

ListItemAdapter(@NonNull context: Context, @NonNull itemProvider: ListItemProvider<ListItem.ViewHolder!>)

Defaults BackgroundStyle to BackgroundStyle#NONE.

<init>

ListItemAdapter(@NonNull context: Context, @NonNull itemProvider: ListItemProvider<ListItem.ViewHolder!>, backgroundStyle: Int)

Public methods

registerListItemViewType

open fun registerListItemViewType(viewType: Int, @LayoutRes layoutResId: Int, function: Function<View!, ListItem.ViewHolder!>!): Unit

Registers a custom ListItem that this adapter will handle. The custom list item will be identified by the unique view id that is passed to this method. The function should a reference to the method that will create the ViewHolder that houses the custom ListItem.

int viewType = -1; registerListItemViewType( viewType, R.layout.custom_view_layout, CustomListItem::createViewHolder); 

The function will receive a view as RecyclerView.ViewHolder#itemView. This view uses a background defined by BackgroundStyle.

Subclasses of ListItem in package androidx.car.widget are already registered.

Parameters
viewType Int: A unique id for the custom view. Use negative values for custom view type.
layoutResId Int: The layout structure that will bs used for the custom view type.
function Int: function to create ViewHolder for viewType.

setMaxItems

open fun setMaxItems(maxItems: Int): Unit

onCreateViewHolder

open fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ListItem.ViewHolder

getItemCount

open fun getItemCount(): Int

start

open fun start(): Unit

Enables support for CarUxRestrictions.

This method can be called from Activity's Activity#onStart(), or at the time of construction.

This method must be accompanied with a matching stop() to avoid leak.

onBindViewHolder

open fun onBindViewHolder(holder: ListItem.ViewHolder, position: Int): Unit

getItemViewType

open fun getItemViewType(position: Int): Int

onAttachedToRecyclerView

open fun onAttachedToRecyclerView(recyclerView: RecyclerView): Unit

getContext

@NonNull open fun getContext(): Context

stop

open fun stop(): Unit

Disables support for CarUxRestrictions, and frees up resources.

This method should be called from Activity's Activity#onStop(), or at the time of this adapter being discarded.

getShowDivider

open fun getShowDivider(position: Int): Boolean