Stay organized with collections Save and categorize content based on your preferences.

GuidedAction

public class GuidedAction extends Action

Known direct subclasses
GuidedDatePickerAction

Subclass of GuidedAction that can choose a date.


A data class which represents an action within a . GuidedActions contain at minimum a title and a description, and typically also an icon.

A GuidedAction typically represents a single action a user may take, but may also represent a possible choice out of a group of mutually exclusive choices (similar to radio buttons), or an information-only label (in which case the item cannot be clicked).

GuidedActions may optionally be checked. They may also indicate that they will request further user input on selection, in which case they will be displayed with a chevron indicator.

GuidedAction recommends to use Builder. When application subclass GuidedAction, it can subclass BuilderBase, implement its own builder() method where it should call applyValues.

Summary

Nested types

Builds a GuidedAction object.

public abstract class GuidedAction.BuilderBase<B extends GuidedAction.BuilderBase>

Base builder class to build a GuidedAction object.

Constants

static final long

Id of standard Cancel action.

static final long

Id of standard Finish action.

static final long

When finishing editing, stay on current action.

static final long

Id of standard Finish action.

static final long

When finishing editing, goes to next action.

static final long

Id of standard No action.

static final long

Id of standard OK action.

static final long

Id of standard Yes action.

static final int

Checkset Id for checkbox.

static final int

Default checkset Id for radio.

static final int

Special check set Id that is neither checkbox nor radio.

Protected constructors

Public methods

String[]

Returns autofill hints, see setAutofillHints.

int

Returns the check set id this action is a part of.

CharSequence

Returns the description of this action.

int

Returns InputType of action description in editing; only valid when isDescriptionEditable is true.

int

Returns InputType of action description not in editing.

CharSequence

Returns the optional description text to edit.

int

Returns InputType of action title in editing; only valid when isEditable is true.

CharSequence

Returns the optional title text to edit.

int

Returns InputType of action title not in editing.

Intent

Returns the intent associated with this action.

List<GuidedAction>
CharSequence

Returns the title of this action.

boolean

Returns whether this action can be activated to edit, e.g. a DatePicker.

boolean

Returns whether this action is has a multiline description.

boolean

Returns whether this action will request further user input when selected, such as showing another GuidedStepFragment or launching a new activity.

boolean
boolean

Returns if this action has editable title or editable description.

boolean

Returns whether the action will only display information and is thus not clickable.

final boolean

Returns true if Action will be saved to instanceState and restored later, false otherwise.

boolean

Returns whether this action is checked.

boolean

Returns whether this action description is editable.

boolean

Returns true if getEditTitle is not null.

boolean

Returns whether this action title is editable.

boolean

Returns whether this action is enabled.

boolean

Returns whether this action is focusable.

void

Restore action from a bundle using a given key.

void

Save action into a bundle using a given key.

void
setChecked(boolean checked)

Sets whether this action is checked.

void

Sets the description of this action.

void

Sets the optional description text to edit instead of setDescription.

void

Sets the optional title text to edit instead of setTitle.

void
setEnabled(boolean enabled)

Sets whether this action is enabled.

void
setFocusable(boolean focusable)

Sets whether this action is focusable.

void
setIntent(Intent intent)

Sets the intent of this action.

void

Change sub actions list.

void

Sets the title of this action.

Inherited Constants

From androidx.leanback.widget.Action
static final long
NO_ID = -1

Indicates that an id has not been set.

Inherited methods

From androidx.leanback.widget.Action
final void
addKeyCode(int keyCode)

Adds a keycode used to invoke this Action.

final Drawable

Returns the icon drawable for this Action.

final long

Returns the id for this Action.

final CharSequence

Returns the first line label for this Action.

final CharSequence

Returns the second line label for this Action.

final void
removeKeyCode(int keyCode)

Removes a keycode used to invoke this Action.

final boolean
respondsToKeyCode(int keyCode)

Returns true if the Action should respond to the given keycode.

final void

Sets the icon drawable for this Action.

final void
setId(long id)

Sets the id for this Action.

final void

Sets the first line label for this Action.

final void

Sets the second line label for this Action.

String

Constants

ACTION_ID_CANCEL

public static final long ACTION_ID_CANCEL = -5

Id of standard Cancel action.

ACTION_ID_CONTINUE

public static final long ACTION_ID_CONTINUE = -7

Id of standard Finish action.

ACTION_ID_CURRENT

public static final long ACTION_ID_CURRENT = -3

When finishing editing, stay on current action.

ACTION_ID_FINISH

public static final long ACTION_ID_FINISH = -6

Id of standard Finish action.

ACTION_ID_NEXT

public static final long ACTION_ID_NEXT = -2

When finishing editing, goes to next action.

ACTION_ID_NO

public static final long ACTION_ID_NO = -9

Id of standard No action.

ACTION_ID_OK

public static final long ACTION_ID_OK = -4

Id of standard OK action.

ACTION_ID_YES

public static final long ACTION_ID_YES = -8

Id of standard Yes action.

CHECKBOX_CHECK_SET_ID

public static final int CHECKBOX_CHECK_SET_ID = -1

Checkset Id for checkbox.

DEFAULT_CHECK_SET_ID

public static final int DEFAULT_CHECK_SET_ID = 1

Default checkset Id for radio.

NO_CHECK_SET

public static final int NO_CHECK_SET = 0

Special check set Id that is neither checkbox nor radio.

Protected constructors

GuidedAction

protected GuidedAction()

Public methods

getAutofillHints

public String[] getAutofillHints()

Returns autofill hints, see setAutofillHints.

getCheckSetId

public int getCheckSetId()

Returns the check set id this action is a part of. All actions in the same list with the same check set id are considered linked. When one of the actions within that set is selected, that action becomes checked, while all the other actions become unchecked.

Returns
int

an integer representing the check set this action is a part of, or CHECKBOX_CHECK_SET_ID if this is a checkbox, or NO_CHECK_SET if this action is not a checkbox or radiobutton.

getDescription

public CharSequence getDescription()

Returns the description of this action.

Returns
CharSequence

The description of this action.

getDescriptionEditInputType

public int getDescriptionEditInputType()

Returns InputType of action description in editing; only valid when isDescriptionEditable is true.

Returns
int

InputType of action description in editing.

getDescriptionInputType

public int getDescriptionInputType()

Returns InputType of action description not in editing.

Returns
int

InputType of action description not in editing.

getEditDescription

public CharSequence getEditDescription()

Returns the optional description text to edit. When not null, it is being edited instead of getDescription.

Returns
CharSequence

Optional description text to edit instead of getDescription.

getEditInputType

public int getEditInputType()

Returns InputType of action title in editing; only valid when isEditable is true.

Returns
int

InputType of action title in editing.

getEditTitle

public CharSequence getEditTitle()

Returns the optional title text to edit. When not null, it is being edited instead of getTitle.

Returns
CharSequence

Optional title text to edit instead of getTitle.

getInputType

public int getInputType()

Returns InputType of action title not in editing.

Returns
int

InputType of action title not in editing.

getIntent

public Intent getIntent()

Returns the intent associated with this action.

Returns
Intent

The intent set when this action was built.

getSubActions

public List<GuidedActiongetSubActions()
Returns
List<GuidedAction>

List of sub actions or null if sub actions list is not enabled.

getTitle

public CharSequence getTitle()

Returns the title of this action.

Returns
CharSequence

The title set when this action was built.

hasEditableActivatorView

public boolean hasEditableActivatorView()

Returns whether this action can be activated to edit, e.g. a DatePicker.

Returns
boolean

true if the action can be activated to edit.

hasMultilineDescription

public boolean hasMultilineDescription()

Returns whether this action is has a multiline description.

Returns
boolean

true if the action was constructed as having a multiline description, false otherwise.

hasNext

public boolean hasNext()

Returns whether this action will request further user input when selected, such as showing another GuidedStepFragment or launching a new activity. Configured during construction.

Returns
boolean

true if the action will request further user input when selected, false otherwise.

hasSubActions

public boolean hasSubActions()
Returns
boolean

True if has sub actions list, even it's currently empty.

hasTextEditable

public boolean hasTextEditable()

Returns if this action has editable title or editable description.

Returns
boolean

True if this action has editable title or editable description, false otherwise.

infoOnly

public boolean infoOnly()

Returns whether the action will only display information and is thus not clickable. If both this and hasNext are true, infoOnly takes precedence. The default is false. For example, this might represent e.g. the amount of storage a document uses, or the cost of an app.

Returns
boolean

true if will only display information, false otherwise.

isAutoSaveRestoreEnabled

public final boolean isAutoSaveRestoreEnabled()

Returns true if Action will be saved to instanceState and restored later, false otherwise. The default value is true. When isAutoSaveRestoreEnabled() is true and getId is not NO_ID:

App may explicitly disable auto restore and handle by itself. App should override Fragment onSaveInstanceState() and onCreateActions()
Returns
boolean

True if Action will be saved to instanceState and restored later, false otherwise.

isChecked

public boolean isChecked()

Returns whether this action is checked.

Returns
boolean

true if the action is currently checked, false otherwise.

isDescriptionEditable

public boolean isDescriptionEditable()

Returns whether this action description is editable.

Returns
boolean

true if the action description is editable, false otherwise.

isEditTitleUsed

public boolean isEditTitleUsed()

Returns true if getEditTitle is not null. When true, the getEditTitle is being edited instead of getTitle.

Returns
boolean

true if getEditTitle is not null.

isEditable

public boolean isEditable()

Returns whether this action title is editable.

Returns
boolean

true if the action title is editable, false otherwise.

isEnabled

public boolean isEnabled()

Returns whether this action is enabled.

Returns
boolean

true if the action is currently enabled, false otherwise.

isFocusable

public boolean isFocusable()

Returns whether this action is focusable.

Returns
boolean

true if the action is currently focusable, false otherwise.

onRestoreInstanceState

public void onRestoreInstanceState(Bundle bundle, String key)

Restore action from a bundle using a given key. When isAutoRestore() is true:

Subclass may override this method.
Parameters
Bundle bundle

Bundle to restore the Action from.

String key

Key used to restore the Action.

onSaveInstanceState

public void onSaveInstanceState(Bundle bundle, String key)

Save action into a bundle using a given key. When isAutoRestoreEna() is true:

Subclass may override this method.
Parameters
Bundle bundle

Bundle to save the Action.

String key

Key used to save the Action.

setChecked

public void setChecked(boolean checked)

Sets whether this action is checked.

Parameters
boolean checked

Whether this action should be checked.

setDescription

public void setDescription(CharSequence description)

Sets the description of this action.

Parameters
CharSequence description

The description of the action.

setEditDescription

public void setEditDescription(CharSequence editDescription)

Sets the optional description text to edit instead of setDescription.

Parameters
CharSequence editDescription

Optional description text to edit instead of setDescription.

setEditTitle

public void setEditTitle(CharSequence editTitle)

Sets the optional title text to edit instead of setTitle.

Parameters
CharSequence editTitle

Optional title text to edit instead of setTitle.

setEnabled

public void setEnabled(boolean enabled)

Sets whether this action is enabled.

Parameters
boolean enabled

Whether this action should be enabled.

setFocusable

public void setFocusable(boolean focusable)

Sets whether this action is focusable.

Parameters
boolean focusable

Whether this action should be focusable.

setIntent

public void setIntent(Intent intent)

Sets the intent of this action.

Parameters
Intent intent

New intent to set on this action.

setSubActions

public void setSubActions(List<GuidedAction> actions)

Change sub actions list.

Parameters
List<GuidedAction> actions

Sub actions list to set on this action. Sets null to disable sub actions.

setTitle

public void setTitle(CharSequence title)

Sets the title of this action.

Parameters
CharSequence title

The title set when this action was built.