Register now for Android Dev Summit 2019!

ActionListItem

public final class ActionListItem
extends ListItem<ActionListItem.ViewHolder>

java.lang.Object
   ↳ 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 ActionListItem.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

class ActionListItem.ViewHolder

Holds the children views of ActionListItem

Constants

int PRIMARY_ACTION_ICON_SIZE_LARGE

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

int PRIMARY_ACTION_ICON_SIZE_MEDIUM

Medium sized icon is slightly bigger than SMALL ones.

int PRIMARY_ACTION_ICON_SIZE_SMALL

Small sized icon is the mostly commonly used size.

Public constructors

ActionListItem(Context context)

Public methods

static ActionListItem.ViewHolder createViewHolder(View itemView)

Creates a ActionListItem.ViewHolder.

int getViewType()

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

void onBind(ActionListItem.ViewHolder viewHolder)

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

void setAction(String text, boolean showDivider, View.OnClickListener listener)

This method is deprecated. Use setPrimaryAction(String, boolean, View.OnClickListener) or setSecondaryAction(String, boolean, View.OnClickListener) instead to individually set the actions.

void setActionBorderless(boolean isActionBorderless)

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

void setActions(String primaryActionText, boolean showPrimaryActionDivider, View.OnClickListener primaryActionOnClickListener, String secondaryActionText, boolean showSecondaryActionDivider, View.OnClickListener secondaryActionOnClickListener)

This method is deprecated. Use setPrimaryAction(String, boolean, View.OnClickListener) and setSecondaryAction(String, boolean, View.OnClickListener) to set both actions.

void setBody(CharSequence body)

Sets the body text of item.

void setEnabled(boolean enabled)

Sets the enabled state of the bound ListItem.ViewHolder.

void setOnClickListener(View.OnClickListener listener)

Sets View.OnClickListener of ActionListItem.

void setPrimaryAction(String primaryActionText, boolean showPrimaryActionDivider, View.OnClickListener primaryActionOnClickListener)

Sets the primary action of this ListItem.

void setPrimaryActionEmptyIcon()

Sets Primary Action to be empty icon.

void setPrimaryActionIcon(int iconResId, int size)

Sets Primary Action to be represented by an icon.

void setPrimaryActionIcon(Drawable drawable, int size)

Sets Primary Action to be represented by an icon.

void setPrimaryActionNoIcon()

Sets Primary Action to have no icon.

void setSecondaryAction(String secondaryActionText, boolean showSecondaryActionDivider, View.OnClickListener secondaryActionOnClickListener)

Sets the secondary action of this ListItem.

void setTitle(CharSequence title)

Sets the title of item.

Protected methods

Context getContext()
void resolveDirtyState()

Calculates the layout params for views in ActionListItem.ViewHolder.

Inherited methods

Constants

PRIMARY_ACTION_ICON_SIZE_LARGE

public static final int PRIMARY_ACTION_ICON_SIZE_LARGE

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

Constant Value: 2 (0x00000002)

PRIMARY_ACTION_ICON_SIZE_MEDIUM

public static final int PRIMARY_ACTION_ICON_SIZE_MEDIUM

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.

Constant Value: 1 (0x00000001)

PRIMARY_ACTION_ICON_SIZE_SMALL

public static final int PRIMARY_ACTION_ICON_SIZE_SMALL

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

Constant Value: 0 (0x00000000)

Public constructors

ActionListItem

public ActionListItem (Context context)

Parameters
context Context

Public methods

createViewHolder

public static ActionListItem.ViewHolder createViewHolder (View itemView)

Creates a ActionListItem.ViewHolder.

Parameters
itemView View

Returns
ActionListItem.ViewHolder

getViewType

public int getViewType ()

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

Returns
int type of this ListItem.

onBind

public void onBind (ActionListItem.ViewHolder viewHolder)

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

Parameters
viewHolder ActionListItem.ViewHolder

setAction

public void setAction (String text, 
                boolean showDivider, 
                View.OnClickListener listener)

This method is 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 boolean: whether to display a vertical bar that separates Text and Action Button.

listener View.OnClickListener: the callback that will run when action button is clicked.

setActionBorderless

public void setActionBorderless (boolean isActionBorderless)

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

public void setActions (String primaryActionText, 
                boolean showPrimaryActionDivider, 
                View.OnClickListener primaryActionOnClickListener, 
                String secondaryActionText, 
                boolean showSecondaryActionDivider, 
                View.OnClickListener secondaryActionOnClickListener)

This method is 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 boolean: Whether or not to show a divider before the primary action.

primaryActionOnClickListener View.OnClickListener: The listener to be invoked when the primary action is triggered.

secondaryActionText String: The secondary action text.

showSecondaryActionDivider boolean: Whether or not to show a divider before the secondary action.

secondaryActionOnClickListener View.OnClickListener: The listener to be invoked when the secondary action is triggered.

setBody

public void setBody (CharSequence body)

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

public void setEnabled (boolean enabled)

Sets the enabled state of the bound ListItem.ViewHolder.

All visible children views of ViewHolder should be set to enabled. Caller is responsible for notifying ListItemAdapter about data change.

Disabled items are usually styled at 50% opacity. Consider similar styling for consistency.

Parameters
enabled boolean

setOnClickListener

public void setOnClickListener (View.OnClickListener listener)

Sets View.OnClickListener of ActionListItem.

Parameters
listener View.OnClickListener

setPrimaryAction

public void setPrimaryAction (String primaryActionText, 
                boolean showPrimaryActionDivider, 
                View.OnClickListener primaryActionOnClickListener)

Sets the primary action of this ListItem.

Parameters
primaryActionText String: Action text to display.

showPrimaryActionDivider boolean: Whether or not to display a vertical bar before the primary action.

primaryActionOnClickListener View.OnClickListener: The callback that will run when the action is clicked.

Throws
IllegalArgumentException If primaryActionText is null or empty.
IllegalArgumentException If primaryActionOnClickListener is null.

setPrimaryActionEmptyIcon

public void setPrimaryActionEmptyIcon ()

Sets Primary Action to be empty icon.

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

setPrimaryActionIcon

public void setPrimaryActionIcon (int iconResId, 
                int size)

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

public void setPrimaryActionIcon (Drawable drawable, 
                int size)

Sets Primary Action to be represented by an icon.

Parameters
drawable Drawable: the Drawable to set, or null to clear the content.

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.

setPrimaryActionNoIcon

public void setPrimaryActionNoIcon ()

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

setSecondaryAction

public void setSecondaryAction (String secondaryActionText, 
                boolean showSecondaryActionDivider, 
                View.OnClickListener secondaryActionOnClickListener)

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 boolean: Whether or not to display a vertical bar before the secondary action.

secondaryActionOnClickListener View.OnClickListener: The callback that will run when the action is clicked.

Throws
IllegalArgumentException If secondaryActionText is null or empty.
IllegalArgumentException If secondaryActionOnClickListener is null.

setTitle

public void setTitle (CharSequence title)

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

protected Context getContext ()

Returns
Context

resolveDirtyState

protected void resolveDirtyState ()

Calculates the layout params for views in ActionListItem.ViewHolder.