CarDrawerAdapter

abstract class CarDrawerAdapter : PagedListView.ItemCap, DrawerItemClickListener
kotlin.Any
   ↳ 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
Unit
setMaxItems(maxItems: Int)

open Unit

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

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

Unit

Int
getItemViewType(position: Int)

Int

open Unit

Enables support for CarUxRestrictions.

open Unit

Disables support for CarUxRestrictions, and frees up resources.

Unit

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

Protected methods
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.

abstract Int

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

Inherited functions

Protected constructors

<init>

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

Public methods

setMaxItems

fun setMaxItems(maxItems: Int): Unit

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.

onCreateViewHolder

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

onBindViewHolder

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

getItemViewType

fun getItemViewType(position: Int): Int

getItemCount

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.

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.

setTitle

fun setTitle(title: CharSequence?): Unit

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

Protected methods

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.

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.