TextListItem

open class TextListItem : ListItem<TextListItem.ViewHolder!>
kotlin.Any
   ↳ 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 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
open

Holds views of TextListItem.

Constants
static Int

Small sized icon is the mostly commonly used size.

static Int

Medium sized icon is slightly bigger than SMALL ones.

static Int

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

Public constructors
<init>(context: Context!)

Public methods
open Unit
setSupplementalIcon(iconResId: Int, showDivider: Boolean)

Sets Supplemental Action to be represented by an Supplemental Icon.

open Unit
setSupplementalIcon(drawable: Drawable!, showDivider: Boolean)

Sets Supplemental Action to be represented by an Supplemental Icon.

open Unit
setSupplementalIcon(iconResId: Int, showDivider: Boolean, listener: OnClickListener!)

Sets Supplemental Action to be represented by an Supplemental Icon.

open Unit
setSupplementalIcon(drawable: Drawable!, showDivider: Boolean, listener: OnClickListener!)

Sets Supplemental Action to be represented by an Supplemental Icon.

open Unit

Sets Primary Action to be empty icon.

open Unit
setEnabled(enabled: Boolean)

open Unit
setTitle(title: String!)

Sets the title of item.

open Unit

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

open Unit
setBody(body: String!)

Sets the body text of item.

open Unit
setBody(body: String!, asPrimary: Boolean)

Sets the body text of item.

open Unit

Sets View.OnClickListener of TextListItem.

open Unit
setPrimaryActionIcon(@DrawableRes iconResId: Int, useLargeIcon: Boolean)

Sets Primary Action to be represented by an icon.

open Unit
setPrimaryActionIcon(drawable: Drawable!, useLargeIcon: Boolean)

Sets Primary Action to be represented by an icon.

open Unit
setPrimaryActionIcon(@DrawableRes iconResId: Int)

Sets Primary Action to be represented by an icon.

open Unit
setPrimaryActionIcon(@Nullable drawable: Drawable?)

Sets Primary Action to be represented by an icon.

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

Sets Primary Action to be represented by an icon.

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

Sets Primary Action to be represented by an icon.

open Unit

Sets Primary Action to have no icon.

open Unit
setSwitchState(isChecked: Boolean)

Sets the state of Switch.

open Unit
setSwitch(checked: Boolean, showDivider: Boolean, listener: OnCheckedChangeListener!)

Sets Supplemental Action to be represented by a android.widget.Switch.

open Unit
setAction(text: String!, showDivider: Boolean, listener: OnClickListener!)

Sets Supplemental Action to be represented by an Action Button.

open Int

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

open Unit

Sets the size of Primary Action Icon.

open Unit
setActions(action1Text: String!, showAction1Divider: Boolean, action1OnClickListener: OnClickListener!, action2Text: String!, showAction2Divider: Boolean, action2OnClickListener: OnClickListener!)

Sets Supplemental Action to be represented by two Action Buttons.

open static TextListItem.ViewHolder!
createViewHolder(itemView: View!)

Creates a TextListItem.ViewHolder.

Protected methods
open Unit

Calculates the layout params for views in ViewHolder.

Inherited functions

Constants

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

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_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

Public constructors

<init>

TextListItem(context: Context!)

Public methods

setSupplementalIcon

open fun setSupplementalIcon(iconResId: Int, showDivider: Boolean): Unit

Sets Supplemental Action to be represented by an Supplemental Icon.

Parameters
iconResId Int: drawable resource id.
showDivider Int: whether to display a vertical bar that separates text and Supplemental Icon.

setSupplementalIcon

open fun setSupplementalIcon(drawable: Drawable!, showDivider: Boolean): Unit

Sets Supplemental Action to be represented by an Supplemental Icon.

Parameters
drawable Drawable!: the Drawable to set, or null to clear the content.
showDivider Drawable!: whether to display a vertical bar that separates text and Supplemental Icon.

setSupplementalIcon

open fun setSupplementalIcon(iconResId: Int, showDivider: Boolean, listener: OnClickListener!): Unit

Sets Supplemental Action to be represented by an Supplemental Icon.

Parameters
iconResId Int: drawable resource id.
showDivider Int: whether to display a vertical bar that separates text and Supplemental Icon.
listener Int: the callback that will run when icon is clicked.

setSupplementalIcon

open fun setSupplementalIcon(drawable: Drawable!, showDivider: Boolean, listener: OnClickListener!): Unit

Sets Supplemental Action to be represented by an Supplemental Icon.

Parameters
drawable Drawable!: the Drawable to set, or null to clear the content.
showDivider Drawable!: whether to display a vertical bar that separates text and Supplemental Icon.
listener Drawable!: the callback that will run when icon is clicked.

setPrimaryActionEmptyIcon

open 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.

setEnabled

open fun setEnabled(enabled: Boolean): Unit

setTitle

open fun setTitle(title: String!): Unit

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.

onBind

open fun onBind(viewHolder: TextListItem.ViewHolder!): Unit

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

setBody

open fun setBody(body: String!): Unit

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.

setBody

open fun setBody(body: String!, asPrimary: Boolean): Unit

Sets the body text of item.

Parameters
body String!: text to be displayed.
asPrimary String!: sets Body Text as primary text of item.

setOnClickListener

open fun setOnClickListener(listener: OnClickListener!): Unit

Sets View.OnClickListener of TextListItem.

setPrimaryActionIcon

open fun setPrimaryActionIcon(@DrawableRes iconResId: Int, useLargeIcon: Boolean): Unit

Sets Primary Action to be represented by an icon.

Parameters
iconResId Int: the resource identifier of the drawable.
useLargeIcon Int: the size of primary icon. Large Icon is a square as tall as an item.

setPrimaryActionIcon

open fun setPrimaryActionIcon(drawable: Drawable!, useLargeIcon: Boolean): Unit

Sets Primary Action to be represented by an icon.

Parameters
drawable Drawable!: the Drawable to set, or null to clear the content.
useLargeIcon Drawable!: the size of primary icon. Large Icon is a square as tall as an item.

setPrimaryActionIcon

open fun setPrimaryActionIcon(@DrawableRes iconResId: Int): Unit

Sets Primary Action to be represented by an icon.

Parameters
iconResId Int: the resource identifier of the drawable.

setPrimaryActionIcon

open fun setPrimaryActionIcon(@Nullable drawable: Drawable?): Unit

Sets Primary Action to be represented by an icon.

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

setPrimaryActionIcon

open 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: small/medium/large. Available as PRIMARY_ACTION_ICON_SIZE_SMALL, PRIMARY_ACTION_ICON_SIZE_MEDIUM, PRIMARY_ACTION_ICON_SIZE_LARGE.

setPrimaryActionIcon

open 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?: small/medium/large. Available as PRIMARY_ACTION_ICON_SIZE_SMALL, PRIMARY_ACTION_ICON_SIZE_MEDIUM, PRIMARY_ACTION_ICON_SIZE_LARGE.

setPrimaryActionNoIcon

open fun setPrimaryActionNoIcon(): Unit

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

setSwitchState

open fun setSwitchState(isChecked: Boolean): Unit

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.

setSwitch

open fun setSwitch(checked: Boolean, showDivider: Boolean, listener: OnCheckedChangeListener!): Unit

Sets Supplemental Action to be represented by a android.widget.Switch.

Parameters
checked Boolean: initial value for switched.
showDivider Boolean: whether to display a vertical bar between switch and text.
listener Boolean: callback to be invoked when the checked state is markDirty.

setAction

open fun setAction(text: String!, showDivider: Boolean, listener: OnClickListener!): Unit

Sets Supplemental Action to be represented by an Action Button.

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.

getViewType

open fun getViewType(): Int

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

Return
Int: type of this ListItem.

setPrimaryActionIconSize

open fun setPrimaryActionIconSize(size: Int): Unit

Sets the size of Primary Action Icon.

Parameters
size Int: small/medium/large. Available as PRIMARY_ACTION_ICON_SIZE_SMALL, PRIMARY_ACTION_ICON_SIZE_MEDIUM, PRIMARY_ACTION_ICON_SIZE_LARGE.

setActions

open fun setActions(action1Text: String!, showAction1Divider: Boolean, action1OnClickListener: OnClickListener!, action2Text: String!, showAction2Divider: Boolean, action2OnClickListener: OnClickListener!): Unit

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.
action2Text String!: button text to display.

createViewHolder

open static fun createViewHolder(itemView: View!): TextListItem.ViewHolder!

Creates a TextListItem.ViewHolder.

Protected methods

resolveDirtyState

protected open fun resolveDirtyState(): Unit

Calculates the layout params for views in ViewHolder.