The Android Developer Challenge is back! Submit your idea before December 2.

CarDrawerAdapter

abstract class CarDrawerAdapter : RecyclerView.Adapter<DrawerItemViewHolder!>, PagedListView.ItemCap
kotlin.Any
   ↳ androidx.recyclerview.widget.RecyclerView.Adapter<androidx.car.drawer.DrawerItemViewHolder>
   ↳ androidx.car.drawer.CarDrawerAdapter

Base adapter for displaying items in the car navigation drawer, which uses a PagedListView.

Subclasses can optionally set the title that will be displayed when displaying the contents of the drawer via setTitle(CharSequence). The title can be updated at any point later on. The title of the root adapter will also be the main title showed in the toolbar when the drawer is closed. See CarDrawerController#setRootAdapter(CarDrawerAdapter) for more information.

This class also takes care of implementing the PageListView.ItemCamp contract and subclasses should implement getActualItemCount().

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

Summary

Inherited constants

Protected constructors

<init>(context: Context!, showDisabledListOnEmpty: Boolean)

Public methods

open Unit

Called when this adapter has been popped off the stack and is no longer needed.

Int

Int
getItemViewType(position: Int)

Unit

DrawerItemViewHolder
onCreateViewHolder(parent: ViewGroup, viewType: Int)

Unit
setMaxItems(maxItems: Int)

Unit
setTitle(@Nullable title: CharSequence?)

Updates the title to display in the toolbar for this Adapter.

open Unit

Enables support for CarUxRestrictions.

open Unit

Disables support for CarUxRestrictions, and frees up resources.

Protected methods

abstract Int

Returns the absolute number of items that can be displayed in the list.

abstract Unit

Subclasses should set all elements in holder to populate the drawer-item.

open Boolean
usesSmallLayout(position: Int)

Used to indicate the layout used for the Drawer item at given position.

Inherited functions

Protected constructors

<init>

protected CarDrawerAdapter(context: Context!, showDisabledListOnEmpty: Boolean)

Public methods

cleanup

open fun cleanup(): Unit

Called when this adapter has been popped off the stack and is no longer needed. Subclasses can override to do any necessary cleanup.

getItemCount

fun getItemCount(): Int

getItemViewType

fun getItemViewType(position: Int): Int

onBindViewHolder

fun onBindViewHolder(holder: DrawerItemViewHolder, position: Int): Unit

onCreateViewHolder

fun onCreateViewHolder(parent: ViewGroup, viewType: Int): DrawerItemViewHolder

setMaxItems

fun setMaxItems(maxItems: Int): Unit

setTitle

fun setTitle(@Nullable title: CharSequence?): Unit

Updates the title to display in the toolbar for this Adapter.

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.

Protected methods

getActualItemCount

protected abstract fun getActualItemCount(): Int

Returns the absolute number of items that can be displayed in the list.

A class should implement this method to supply the number of items to be displayed. Returning 0 from this method will cause an empty list icon to be displayed in the drawer.

A class should override this method rather than getItemCount() because that method is handling the logic of when to display the empty list icon. It will return 1 when getActualItemCount() returns 0.

Return
Int: The number of items to be displayed in the list.

populateViewHolder

protected abstract fun populateViewHolder(holder: DrawerItemViewHolder!, position: Int): Unit

Subclasses should set all elements in holder to populate the drawer-item. If some element is not used, it should be nulled out since these ViewHolder/View's are recycled.

usesSmallLayout

protected open fun usesSmallLayout(position: Int): Boolean

Used to indicate the layout used for the Drawer item at given position. Subclasses can override this to use normal layout which includes text element below title.

A small layout is presented by the layout R.layout.car_drawer_list_item_small. Otherwise, the layout R.layout.car_drawer_list_item_normal will be used.

Parameters
position Int: Adapter position of item.
Return
Boolean: Whether the item at this position will use a small layout (default) or normal layout.