Register now for Android Dev Summit 2019!

RadioButtonListItem

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

Class to build a list item with RadioButton.

A radio button list item visually composes of 3 parts.

  • optional Primary Action Icon.
  • optional Text.
  • A RadioButton.

Clicking the item always checks the radio button.

Summary

Nested classes

Holds views of RadioButtonListItem.

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 RadioButtonListItem.ViewHolder
createViewHolder(@NonNull itemView: View)

Creates a RadioButtonListItem.ViewHolder.

open Int

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

open Boolean

Get whether the radio button is checked.

open Unit
setChecked(isChecked: Boolean)

Sets the state of radio button.

open Unit
setEnabled(enabled: Boolean)

open Unit

Sets android.widget.CompoundButton.OnCheckedChangeListener of radio button.

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

Sets Primary Action to be represented by an icon.

open Unit

Sets whether to display a vertical bar that separates text and radio button.

open Unit
setText(@Nullable text: CharSequence?)

Sets text to be displayed next to icon.

open Unit
setTextStartMargin(@DimenRes dimenRes: Int)

Sets the start margin of text.

Protected methods

open Context

open Unit

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

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.

Value: 0

Public constructors

<init>

RadioButtonListItem(@NonNull context: Context)

Public methods

createViewHolder

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

Creates a RadioButtonListItem.ViewHolder.

getViewType

open fun getViewType(): Int

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

Return
Int: type of this ListItem.

isChecked

open fun isChecked(): Boolean

Get whether the radio button is checked.

The return value is in sync with UI state.

Return
Boolean: true if the widget is checked; false otherwise.

setChecked

open fun setChecked(isChecked: Boolean): Unit

Sets the state of radio button.

Parameters
isChecked Boolean: true to check the button; false to uncheck it.

setEnabled

open fun setEnabled(enabled: Boolean): Unit

setOnCheckedChangeListener

open fun setOnCheckedChangeListener(@NonNull listener: OnCheckedChangeListener): Unit

Sets android.widget.CompoundButton.OnCheckedChangeListener of radio button.

setPrimaryActionIcon

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

Sets Primary Action to be represented by an icon. The size of icon automatically adjusts the start of Text.

Parameters
icon Icon: the icon to set as primary action. Setting null clears the icon and aligns text to the start of list item; size will be ignored.
size Icon: constant that represents the size of icon. See PRIMARY_ACTION_ICON_SIZE_SMALL, PRIMARY_ACTION_ICON_SIZE_MEDIUM, and PRIMARY_ACTION_ICON_SIZE_LARGE. If null is passed in for icon, size will be ignored.

setShowRadioButtonDivider

open fun setShowRadioButtonDivider(showDivider: Boolean): Unit

Sets whether to display a vertical bar that separates text and radio button.

setText

open fun setText(@Nullable text: CharSequence?): Unit

Sets text to be displayed next to icon.

Parameters
text CharSequence?: Text to be displayed, or null to clear the content.

setTextStartMargin

open fun setTextStartMargin(@DimenRes dimenRes: Int): Unit

Sets the start margin of text.

Protected methods

getContext

@NonNull protected open fun getContext(): Context

onBind

protected open fun onBind(viewHolder: RadioButtonListItem.ViewHolder!): Unit

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

resolveDirtyState

protected open fun resolveDirtyState(): Unit

Calculates the layout params for views in ViewHolder.