Register now for Android Dev Summit 2019!

ActionListItem

class ActionListItem : ListItem<ActionListItem.ViewHolder!>
kotlin.Any
   ↳ androidx.car.widget.ListItem<androidx.car.widget.ActionListItem.ViewHolder>
   ↳ androidx.car.widget.ActionListItem

Class to build a list item that has up to two actions.

An item visually composes of 3 parts; each part may contain multiple views.

  • Primary Action: represented by an icon of following types.
    • Primary Icon - icon size could be large or small.
    • No Icon - no icon is shown.
    • Empty Icon - Text offsets start space as if there was an icon.
  • Text: supports any combination of the following text views.
    • Title
    • Body
  • Supplemental Action: Up to two actions.

ActionListItem binds data to ViewHolder based on components selected.

When conflicting setter methods are called (e.g. setting primary action to both primary icon and no icon), the last called method wins.

Summary

Nested classes

Holds the children views of ActionListItem.

Constants

static Int

Large sized icon is as tall as a list item with only title text.

static Int

Medium sized icon is slightly bigger than SMALL ones.

static Int

Small sized icon is the mostly commonly used size.

Public constructors

<init>(@NonNull context: Context)

Public methods

static ActionListItem.ViewHolder
createViewHolder(itemView: View!)

Creates a ActionListItem.ViewHolder.

Int

Used by ListItemAdapter to choose layout to inflate for view holder.

Unit

Resets all views in ActionListItem.ViewHolder then applies ViewBinders to adjust view layout params.

Unit
setAction(@NonNull text: String, showDivider: Boolean, @NonNull listener: OnClickListener)

Sets the primary action of this ListItem.

Unit
setActionBorderless(isActionBorderless: Boolean)

Sets whether or not the actions should be styled as borderless.

Unit
setActions(@NonNull primaryActionText: String, showPrimaryActionDivider: Boolean, @NonNull primaryActionOnClickListener: OnClickListener, @NonNull secondaryActionText: String, showSecondaryActionDivider: Boolean, @NonNull secondaryActionOnClickListener: OnClickListener)

Sets the primary and secondary actions for this ListItem.

Unit
setBody(@NonNull body: CharSequence)

Sets the body text of item.

Unit
setEnabled(enabled: Boolean)

Unit

Sets View.OnClickListener of ActionListItem.

Unit
setPrimaryAction(@NonNull primaryActionText: String, showPrimaryActionDivider: Boolean, @NonNull primaryActionOnClickListener: OnClickListener)

Sets the primary action of this ListItem.

Unit

Sets Primary Action to be empty icon.

Unit
setPrimaryActionIcon(@DrawableRes iconResId: Int, size: Int)

Sets Primary Action to be represented by an icon.

Unit
setPrimaryActionIcon(@Nullable drawable: Drawable?, size: Int)

Sets Primary Action to be represented by an icon.

Unit

Sets Primary Action to have no icon.

Unit
setSecondaryAction(@NonNull secondaryActionText: String, showSecondaryActionDivider: Boolean, @NonNull secondaryActionOnClickListener: OnClickListener)

Sets the secondary action of this ListItem.

Unit
setTitle(@NonNull title: CharSequence)

Sets the title of item.

Protected methods

Context

Unit

Calculates the layout params for views in ViewHolder.

Inherited functions

Constants

PRIMARY_ACTION_ICON_SIZE_LARGE

static val PRIMARY_ACTION_ICON_SIZE_LARGE: Int

Large sized icon is as tall as a list item with only title text. It is intended for album art.

Value: 2

PRIMARY_ACTION_ICON_SIZE_MEDIUM

static val PRIMARY_ACTION_ICON_SIZE_MEDIUM: Int

Medium sized icon is slightly bigger than SMALL ones. It is intended for profile pictures (avatar), in which case caller is responsible for passing in a circular image.

Value: 1

PRIMARY_ACTION_ICON_SIZE_SMALL

static val PRIMARY_ACTION_ICON_SIZE_SMALL: Int

Small sized icon is the mostly commonly used size. It's the same as supplemental action icon.

Value: 0

Public constructors

<init>

ActionListItem(@NonNull context: Context)

Public methods

createViewHolder

@NonNull static fun createViewHolder(itemView: View!): ActionListItem.ViewHolder

Creates a ActionListItem.ViewHolder.

getViewType

fun getViewType(): Int

Used by ListItemAdapter to choose layout to inflate for view holder.

Return
Int: type of this ListItem.

onBind

fun onBind(viewHolder: ActionListItem.ViewHolder!): Unit

Resets all views in ActionListItem.ViewHolder then applies ViewBinders to adjust view layout params.

setAction

fun setAction(@NonNull text: String, showDivider: Boolean, @NonNull listener: OnClickListener): Unit

Deprecated: Use setPrimaryAction(String, boolean, View.OnClickListener) or setSecondaryAction(String, boolean, View.OnClickListener) instead to individually set the actions.

Sets the primary action of this ListItem.

Parameters
text String: button text to display.
showDivider String: whether to display a vertical bar that separates Text and Action Button.
listener String: the callback that will run when action button is clicked.

setActionBorderless

fun setActionBorderless(isActionBorderless: Boolean): Unit

Sets whether or not the actions should be styled as borderless.

By default, this value is true.

Parameters
isActionBorderless Boolean: true if the actions should be borderless. false otherwise.

setActions

fun setActions(@NonNull primaryActionText: String, showPrimaryActionDivider: Boolean, @NonNull primaryActionOnClickListener: OnClickListener, @NonNull secondaryActionText: String, showSecondaryActionDivider: Boolean, @NonNull secondaryActionOnClickListener: OnClickListener): Unit

Deprecated: Use setPrimaryAction(String, boolean, View.OnClickListener) and setSecondaryAction(String, boolean, View.OnClickListener) to set both actions.

Sets the primary and secondary actions for this ListItem.

Parameters
primaryActionText String: The primary action text.
showPrimaryActionDivider String: Whether or not to show a divider before the primary action.
primaryActionOnClickListener String: The listener to be invoked when the primary action is triggered.
secondaryActionText String: The secondary action text.
showSecondaryActionDivider String: Whether or not to show a divider before the secondary action.
secondaryActionOnClickListener String: The listener to be invoked when the secondary action is triggered.

setBody

fun setBody(@NonNull body: CharSequence): Unit

Sets the body text of item.

Text beyond length required by regulation will be truncated. Defaults Title text as the primary.

Parameters
body CharSequence: text to be displayed.

setEnabled

fun setEnabled(enabled: Boolean): Unit

setOnClickListener

fun setOnClickListener(listener: OnClickListener!): Unit

Sets View.OnClickListener of ActionListItem.

setPrimaryAction

fun setPrimaryAction(@NonNull primaryActionText: String, showPrimaryActionDivider: Boolean, @NonNull primaryActionOnClickListener: OnClickListener): Unit

Sets the primary action of this ListItem.

Parameters
primaryActionText String: Action text to display.
showPrimaryActionDivider String: Whether or not to display a vertical bar before the primary action.
primaryActionOnClickListener String: The callback that will run when the action is clicked.
Exceptions
IllegalArgumentException If primaryActionOnClickListener is null.

setPrimaryActionEmptyIcon

fun setPrimaryActionEmptyIcon(): Unit

Sets Primary Action to be empty icon.

Text would have a start margin as if Primary Action were set to primary icon.

setPrimaryActionIcon

fun setPrimaryActionIcon(@DrawableRes iconResId: Int, size: Int): Unit

Sets Primary Action to be represented by an icon.

Parameters
iconResId Int: the resource identifier of the drawable.
size Int: The size of the icon. Must be one of PRIMARY_ACTION_ICON_SIZE_SMALL, PRIMARY_ACTION_ICON_SIZE_MEDIUM, or PRIMARY_ACTION_ICON_SIZE_LARGE.

setPrimaryActionIcon

fun setPrimaryActionIcon(@Nullable drawable: Drawable?, size: Int): Unit

Sets Primary Action to be represented by an icon.

Parameters
drawable Drawable?: the Drawable to set, or null to clear the content.
size Drawable?: The size of the icon. Must be one of PRIMARY_ACTION_ICON_SIZE_SMALL, PRIMARY_ACTION_ICON_SIZE_MEDIUM, or PRIMARY_ACTION_ICON_SIZE_LARGE.

setPrimaryActionNoIcon

fun setPrimaryActionNoIcon(): Unit

Sets Primary Action to have no icon. Text would align to the start of item.

setSecondaryAction

fun setSecondaryAction(@NonNull secondaryActionText: String, showSecondaryActionDivider: Boolean, @NonNull secondaryActionOnClickListener: OnClickListener): Unit

Sets the secondary action of this ListItem.

The secondary action will appear before the primary action if both are set.

Parameters
secondaryActionText String: Action text to display.
showSecondaryActionDivider String: Whether or not to display a vertical bar before the secondary action.
secondaryActionOnClickListener String: The callback that will run when the action is clicked.
Exceptions
IllegalArgumentException If secondaryActionOnClickListener is null.

setTitle

fun setTitle(@NonNull title: CharSequence): Unit

Sets the title of item.

Title text is limited to one line, and ellipsizes at the end.

Parameters
title CharSequence: text to display as title.

Protected methods

getContext

@NonNull protected fun getContext(): Context

resolveDirtyState

protected fun resolveDirtyState(): Unit

Calculates the layout params for views in ViewHolder.