Android Dev Summit, October 23-24: two days of technical content, directly from the Android team. Sign-up for livestream updates.

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

Holds views of TextListItem.

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

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

Creates a TextListItem.ViewHolder.

open Int

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

open Unit

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

open Unit

Sets the body text of item.

open Unit
setEnabled(enabled: Boolean)

open Unit

Sets View.OnClickListener of TextListItem.

open Unit

Sets Primary Action to be empty icon.

open Unit
setPrimaryActionIcon(@NonNull icon: Icon, size: Int)

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
setSupplementalIcon(@NonNull icon: Icon, showDivider: Boolean)

Sets Supplemental Action to be represented by an Supplemental Icon.

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 an OnClickListener for the icon representing the Supplemental Action.

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

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

open Unit
setSwitchState(isChecked: Boolean)

Sets the state of Switch.

open Unit

Sets the title of item.

Protected methods

open Context

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

TextListItem(@NonNull context: Context)

Public methods

createViewHolder

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

Creates a TextListItem.ViewHolder.

getViewType

open fun getViewType(): Int

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

Return
Int: type of this ListItem.

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: CharSequence!): Unit

Sets the body text of item.

Text beyond length required by regulation will be truncated.

Parameters
body CharSequence!: text to be displayed.

setEnabled

open fun setEnabled(enabled: Boolean): Unit

setOnClickListener

open fun setOnClickListener(listener: OnClickListener!): Unit

Sets View.OnClickListener of TextListItem.

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.

setPrimaryActionIcon

open fun setPrimaryActionIcon(@NonNull icon: Icon, size: Int): Unit

Sets Primary Action to be represented by an icon.

Parameters
icon Icon: An icon to set as primary action.
size Icon: small/medium/large. Available as PRIMARY_ACTION_ICON_SIZE_SMALL, PRIMARY_ACTION_ICON_SIZE_MEDIUM, PRIMARY_ACTION_ICON_SIZE_LARGE.

setPrimaryActionIcon

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

Deprecated: Use setPrimaryActionIcon(Icon, int).

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

Deprecated: Use setPrimaryActionIcon(Icon, int).

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.

setSupplementalIcon

open fun setSupplementalIcon(@NonNull icon: Icon, showDivider: Boolean): Unit

Sets Supplemental Action to be represented by an Supplemental Icon.

Parameters
icon Icon: An icon to set as supplemental action.
showDivider Icon: whether to display a vertical bar that separates text and Supplemental Icon.

setSupplementalIcon

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

Deprecated: Use setSupplementalIcon(Icon, boolean).

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

Deprecated: Use setSupplementalIcon(Icon, boolean).

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

Deprecated: Use setSupplementalIcon(Icon, boolean) and setSupplementalIconOnClickListener(View.OnClickListener).

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

Deprecated: Use setSupplementalIcon(Icon, boolean) and setSupplementalIconOnClickListener(View.OnClickListener).

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.

setSupplementalIconOnClickListener

open fun setSupplementalIconOnClickListener(@NonNull listener: OnClickListener): Unit

Sets an OnClickListener for the icon representing the Supplemental Action.

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

setSwitch

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

Deprecated: Use SwitchListItem instead.

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 shown in the UI changes.

setSwitchState

open fun setSwitchState(isChecked: Boolean): Unit

Deprecated: Use SwitchListItem instead.

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

open fun setTitle(title: CharSequence!): Unit

Sets the title of item.

Primary text is Title by default. It can be set by setBody(CharSequence)

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

Parameters
title CharSequence!: text to display as title.

Protected methods

getContext

@NonNull protected open fun getContext(): Context

resolveDirtyState

protected open fun resolveDirtyState(): Unit

Calculates the layout params for views in ViewHolder.