belongs to Maven artifact androidx.car:car:1.0.0-alpha1

TextListItem

public class TextListItem
extends ListItem<TextListItem.ViewHolder>

java.lang.Object
   ↳ androidx.car.widget.ListItem<androidx.car.widget.TextListItem.ViewHolder>
     ↳ androidx.car.widget.TextListItem


Class to build a list item of text.

An item supports primary action and supplemental action(s).

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: represented by one of the following types; aligned toward the end of item.
    • Supplemental Icon
    • One Action Button
    • Two Action Buttons
    • Switch

TextListItem binds data to TextListItem.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 TextListItem.ViewHolder

Holds views of TextListItem. 

Public constructors

TextListItem(Context context)

Public methods

static TextListItem.ViewHolder createViewHolder(View itemView)

Creates a TextListItem.ViewHolder.

int getViewType()

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

void onBind(TextListItem.ViewHolder viewHolder)

Hides all views in TextListItem.ViewHolder then applies ViewBinders to adjust view layout params.

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

Sets Supplemental Action to be represented by an Action Button.

void setActions(String action1Text, boolean showAction1Divider, View.OnClickListener action1OnClickListener, String action2Text, boolean showAction2Divider, View.OnClickListener action2OnClickListener)

Sets Supplemental Action to be represented by two Action Buttons.

void setBody(String body, boolean asPrimary)

Sets the body text of item.

void setBody(String body)

Sets the body text of item.

void setOnClickListener(View.OnClickListener listener)

Sets View.OnClickListener of TextListItem.

void setPrimaryActionEmptyIcon()

Sets Primary Action to be empty icon.

void setPrimaryActionIcon(Drawable drawable, boolean useLargeIcon)

Sets Primary Action to be represented by an icon.

void setPrimaryActionIcon(int iconResId, boolean useLargeIcon)

Sets Primary Action to be represented by an icon.

void setPrimaryActionNoIcon()

Sets Primary Action to have no icon.

void setSupplementalIcon(int iconResId, boolean showDivider)

Sets Supplemental Action to be represented by an Supplemental Icon.

void setSupplementalIcon(Drawable drawable, boolean showDivider)

Sets Supplemental Action to be represented by an Supplemental Icon.

void setSupplementalIcon(Drawable drawable, boolean showDivider, View.OnClickListener listener)

Sets Supplemental Action to be represented by an Supplemental Icon.

void setSupplementalIcon(int iconResId, boolean showDivider, View.OnClickListener listener)

Sets Supplemental Action to be represented by an Supplemental Icon.

void setSwitch(boolean checked, boolean showDivider, CompoundButton.OnCheckedChangeListener listener)

Sets Supplemental Action to be represented by a Switch.

void setSwitchState(boolean isChecked)

Sets the state of Switch.

void setTitle(String title)

Sets the title of item.

Protected methods

void resolveDirtyState()

Calculates the layout params for views in TextListItem.ViewHolder.

Inherited methods

Public constructors

TextListItem

TextListItem (Context context)

Parameters
context Context

Public methods

createViewHolder

TextListItem.ViewHolder createViewHolder (View itemView)

Creates a TextListItem.ViewHolder.

Parameters
itemView View

Returns
TextListItem.ViewHolder

getViewType

int getViewType ()

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

Returns
int type of this ListItem.

onBind

void onBind (TextListItem.ViewHolder viewHolder)

Hides all views in TextListItem.ViewHolder then applies ViewBinders to adjust view layout params.

Parameters
viewHolder TextListItem.ViewHolder

setAction

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

Sets Supplemental Action to be represented by an Action Button.

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.

setActions

void setActions (String action1Text, 
                boolean showAction1Divider, 
                View.OnClickListener action1OnClickListener, 
                String action2Text, 
                boolean showAction2Divider, 
                View.OnClickListener action2OnClickListener)

Sets Supplemental Action to be represented by two Action Buttons.

These two action buttons will be aligned towards item end.

Parameters
action1Text String: button text to display - this button will be closer to item end.

showAction1Divider boolean

action1OnClickListener View.OnClickListener

action2Text String: button text to display.

showAction2Divider boolean

action2OnClickListener View.OnClickListener

setBody

void setBody (String body, 
                boolean asPrimary)

Sets the body text of item.

Parameters
body String: text to be displayed.

asPrimary boolean: sets Body Text as primary text of item.

setBody

void setBody (String body)

Sets the body text of item.

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

Parameters
body String: text to be displayed.

setOnClickListener

void setOnClickListener (View.OnClickListener listener)

Sets View.OnClickListener of TextListItem.

Parameters
listener View.OnClickListener

setPrimaryActionEmptyIcon

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

void setPrimaryActionIcon (Drawable drawable, 
                boolean useLargeIcon)

Sets Primary Action to be represented by an icon.

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

useLargeIcon boolean: the size of primary icon. Large Icon is a square as tall as an item.

setPrimaryActionIcon

void setPrimaryActionIcon (int iconResId, 
                boolean useLargeIcon)

Sets Primary Action to be represented by an icon.

Parameters
iconResId int: the resource identifier of the drawable.

useLargeIcon boolean: the size of primary icon. Large Icon is a square as tall as an item.

setPrimaryActionNoIcon

void setPrimaryActionNoIcon ()

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

setSupplementalIcon

void setSupplementalIcon (int iconResId, 
                boolean showDivider)

Sets Supplemental Action to be represented by an Supplemental Icon.

Parameters
iconResId int: drawable resource id.

showDivider boolean: whether to display a vertical bar that separates text and Supplemental Icon.

setSupplementalIcon

void setSupplementalIcon (Drawable drawable, 
                boolean showDivider)

Sets Supplemental Action to be represented by an Supplemental Icon.

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

showDivider boolean: whether to display a vertical bar that separates text and Supplemental Icon.

setSupplementalIcon

void setSupplementalIcon (Drawable drawable, 
                boolean showDivider, 
                View.OnClickListener listener)

Sets Supplemental Action to be represented by an Supplemental Icon.

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

showDivider boolean: whether to display a vertical bar that separates text and Supplemental Icon.

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

setSupplementalIcon

void setSupplementalIcon (int iconResId, 
                boolean showDivider, 
                View.OnClickListener listener)

Sets Supplemental Action to be represented by an Supplemental Icon.

Parameters
iconResId int: drawable resource id.

showDivider boolean: whether to display a vertical bar that separates text and Supplemental Icon.

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

setSwitch

void setSwitch (boolean checked, 
                boolean showDivider, 
                CompoundButton.OnCheckedChangeListener listener)

Sets Supplemental Action to be represented by a Switch.

Parameters
checked boolean: initial value for switched.

showDivider boolean: whether to display a vertical bar between switch and text.

listener CompoundButton.OnCheckedChangeListener: callback to be invoked when the checked state is markDirty.

setSwitchState

void setSwitchState (boolean isChecked)

Sets the state of Switch. For this method to take effect, setSwitch(boolean, boolean, CompoundButton.OnCheckedChangeListener) must be called first to set Supplemental Action as a Switch.

Parameters
isChecked boolean: sets the "checked/unchecked, namely on/off" state of switch.

setTitle

void setTitle (String title)

Sets the title of item.

Primary text is Title by default. It can be set by setBody(String, boolean)

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

Parameters
title String: text to display as title.

Protected methods

resolveDirtyState

void resolveDirtyState ()

Calculates the layout params for views in TextListItem.ViewHolder.