RadioButtonListItem
public
class
RadioButtonListItem
extends ListItem<RadioButtonListItem.ViewHolder>
java.lang.Object | ||
↳ | 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 | |
---|---|
class |
RadioButtonListItem.ViewHolder
Holds views of RadioButtonListItem. |
Constants | |
---|---|
int |
PRIMARY_ACTION_ICON_SIZE_LARGE
Large sized icon is as tall as a list item with only |
int |
PRIMARY_ACTION_ICON_SIZE_MEDIUM
Medium sized icon is slightly bigger than |
int |
PRIMARY_ACTION_ICON_SIZE_SMALL
Small sized icon is the mostly commonly used size. |
Public constructors | |
---|---|
RadioButtonListItem(Context context)
|
Public methods | |
---|---|
static
RadioButtonListItem.ViewHolder
|
createViewHolder(View itemView)
Creates a |
int
|
getViewType()
Used by |
boolean
|
isChecked()
Get whether the radio button is checked. |
void
|
setChecked(boolean isChecked)
Sets the state of radio button. |
void
|
setEnabled(boolean enabled)
Sets the enabled state of the bound |
void
|
setOnCheckedChangeListener(CompoundButton.OnCheckedChangeListener listener)
Sets |
void
|
setPrimaryActionIcon(Icon icon, int size)
Sets |
void
|
setShowRadioButtonDivider(boolean showDivider)
Sets whether to display a vertical bar that separates |
void
|
setText(CharSequence text)
Sets text to be displayed next to icon. |
void
|
setTextStartMargin(int dimenRes)
Sets the start margin of text. |
Protected methods | |
---|---|
Context
|
getContext()
|
void
|
onBind(RadioButtonListItem.ViewHolder viewHolder)
Hides all views in |
void
|
resolveDirtyState()
Calculates the layout params for views in |
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.
Constant Value: 0 (0x00000000)
Public constructors
Public methods
createViewHolder
public static RadioButtonListItem.ViewHolder createViewHolder (View itemView)
Creates a RadioButtonListItem.ViewHolder
.
Parameters | |
---|---|
itemView |
View |
Returns | |
---|---|
RadioButtonListItem.ViewHolder |
getViewType
public int getViewType ()
Used by ListItemAdapter
to choose layout to inflate for view holder.
Returns | |
---|---|
int |
type of this ListItem. |
isChecked
public boolean isChecked ()
Get whether the radio button is checked.
The return value is in sync with UI state.
Returns | |
---|---|
boolean |
true if the widget is checked; false otherwise.
|
setChecked
public void setChecked (boolean isChecked)
Sets the state of radio button.
Parameters | |
---|---|
isChecked |
boolean : true to check the button; false to uncheck it.
|
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 |
setOnCheckedChangeListener
public void setOnCheckedChangeListener (CompoundButton.OnCheckedChangeListener listener)
Sets CompoundButton.OnCheckedChangeListener
of radio button.
Parameters | |
---|---|
listener |
CompoundButton.OnCheckedChangeListener |
setPrimaryActionIcon
public void setPrimaryActionIcon (Icon icon, int size)
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 |
int : 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
public void setShowRadioButtonDivider (boolean showDivider)
Sets whether to display a vertical bar that separates text
and radio button.
Parameters | |
---|---|
showDivider |
boolean |
setText
public void setText (CharSequence text)
Sets text to be displayed next to icon.
Parameters | |
---|---|
text |
CharSequence : Text to be displayed, or null to clear the content.
|
setTextStartMargin
public void setTextStartMargin (int dimenRes)
Sets the start margin of text.
Parameters | |
---|---|
dimenRes |
int |
Protected methods
onBind
protected void onBind (RadioButtonListItem.ViewHolder viewHolder)
Hides all views in RadioButtonListItem.ViewHolder
then applies ViewBinders to adjust view layout params.
Parameters | |
---|---|
viewHolder |
RadioButtonListItem.ViewHolder |
resolveDirtyState
protected void resolveDirtyState ()
Calculates the layout params for views in RadioButtonListItem.ViewHolder
.
Content and code samples on this page are subject to the licenses described in the Content License. Java is a registered trademark of Oracle and/or its affiliates.