Android Dev Summit, October 23-24: two days of technical content, directly from the Android team. Sign-up for livestream updates.

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 Context

open Int

open Int
getItemViewType(position: Int)

open Boolean
getShowDivider(position: Int)

open Unit

open Unit

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

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 Unit

Enables support for CarUxRestrictions.

open Unit

Disables support for CarUxRestrictions, and frees up resources.

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

getContext

@NonNull open fun getContext(): Context

getItemCount

open fun getItemCount(): Int

getItemViewType

open fun getItemViewType(position: Int): Int

getShowDivider

open fun getShowDivider(position: Int): Boolean

onAttachedToRecyclerView

open fun onAttachedToRecyclerView(recyclerView: RecyclerView): Unit

onBindViewHolder

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

onCreateViewHolder

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

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.

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

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

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.

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.