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.

@Nullable 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.

@Nullable CharSequence

Returns the optional description text to edit.

int

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

@Nullable CharSequence

Returns the optional title text to edit.

int

Returns InputType of action title not in editing.

@Nullable Intent

Returns the intent associated with this action.

@Nullable List<GuidedAction>
@Nullable 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

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 @Nullable Drawable

Returns the icon drawable for this Action.

final long

Returns the id for this Action.

final @Nullable CharSequence

Returns the first line label for this Action.

final @Nullable 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.

@NonNull String

Constants

ACTION_ID_CANCEL

Added in 1.1.0
public static final long ACTION_ID_CANCEL = -5

Id of standard Cancel action.

ACTION_ID_CONTINUE

Added in 1.1.0
public static final long ACTION_ID_CONTINUE = -7

Id of standard Finish action.

ACTION_ID_CURRENT

Added in 1.1.0
public static final long ACTION_ID_CURRENT = -3

When finishing editing, stay on current action.

ACTION_ID_FINISH

Added in 1.1.0
public static final long ACTION_ID_FINISH = -6

Id of standard Finish action.

ACTION_ID_NEXT

Added in 1.1.0
public static final long ACTION_ID_NEXT = -2

When finishing editing, goes to next action.

ACTION_ID_NO

Added in 1.1.0
public static final long ACTION_ID_NO = -9

Id of standard No action.

ACTION_ID_OK

Added in 1.1.0
public static final long ACTION_ID_OK = -4

Id of standard OK action.

ACTION_ID_YES

Added in 1.1.0
public static final long ACTION_ID_YES = -8

Id of standard Yes action.

CHECKBOX_CHECK_SET_ID

Added in 1.1.0
public static final int CHECKBOX_CHECK_SET_ID = -1

Checkset Id for checkbox.

DEFAULT_CHECK_SET_ID

Added in 1.1.0
public static final int DEFAULT_CHECK_SET_ID = 1

Default checkset Id for radio.

NO_CHECK_SET

Added in 1.1.0
public static final int NO_CHECK_SET = 0

Special check set Id that is neither checkbox nor radio.

Protected constructors

GuidedAction

Added in 1.1.0
protected GuidedAction()

Public methods

getAutofillHints

Added in 1.1.0
public String[] getAutofillHints()

Returns autofill hints, see setAutofillHints.

getCheckSetId

Added in 1.1.0
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

Added in 1.1.0
public @Nullable CharSequence getDescription()

Returns the description of this action.

Returns
@Nullable CharSequence

The description of this action.

getDescriptionEditInputType

Added in 1.1.0
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

Added in 1.1.0
public int getDescriptionInputType()

Returns InputType of action description not in editing.

Returns
int

InputType of action description not in editing.

getEditDescription

Added in 1.1.0
public @Nullable CharSequence getEditDescription()

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

Returns
@Nullable CharSequence

Optional description text to edit instead of getDescription.

getEditInputType

Added in 1.1.0
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

Added in 1.1.0
public @Nullable CharSequence getEditTitle()

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

Returns
@Nullable CharSequence

Optional title text to edit instead of getTitle.

getInputType

Added in 1.1.0
public int getInputType()

Returns InputType of action title not in editing.

Returns
int

InputType of action title not in editing.

getIntent

Added in 1.1.0
public @Nullable Intent getIntent()

Returns the intent associated with this action.

Returns
@Nullable Intent

The intent set when this action was built.

getSubActions

Added in 1.1.0
public @Nullable List<GuidedActiongetSubActions()
Returns
@Nullable List<GuidedAction>

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

getTitle

Added in 1.1.0
public @Nullable CharSequence getTitle()

Returns the title of this action.

Returns
@Nullable CharSequence

The title set when this action was built.

hasEditableActivatorView

Added in 1.1.0
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

Added in 1.1.0
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

Added in 1.1.0
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

Added in 1.1.0
public boolean hasSubActions()
Returns
boolean

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

hasTextEditable

Added in 1.1.0
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

Added in 1.1.0
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

Added in 1.1.0
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

Added in 1.1.0
public boolean isChecked()

Returns whether this action is checked.

Returns
boolean

true if the action is currently checked, false otherwise.

isDescriptionEditable

Added in 1.1.0
public boolean isDescriptionEditable()

Returns whether this action description is editable.

Returns
boolean

true if the action description is editable, false otherwise.

isEditTitleUsed

Added in 1.1.0
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

Added in 1.1.0
public boolean isEditable()

Returns whether this action title is editable.

Returns
boolean

true if the action title is editable, false otherwise.

isEnabled

Added in 1.1.0
public boolean isEnabled()

Returns whether this action is enabled.

Returns
boolean

true if the action is currently enabled, false otherwise.

isFocusable

Added in 1.1.0
public boolean isFocusable()

Returns whether this action is focusable.

Returns
boolean

true if the action is currently focusable, false otherwise.

onRestoreInstanceState

Added in 1.1.0
public void onRestoreInstanceState(@NonNull Bundle bundle, @NonNull String key)

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

Subclass may override this method.
Parameters
@NonNull Bundle bundle

Bundle to restore the Action from.

@NonNull String key

Key used to restore the Action.

onSaveInstanceState

Added in 1.1.0
public void onSaveInstanceState(@NonNull Bundle bundle, @NonNull String key)

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

Subclass may override this method.
Parameters
@NonNull Bundle bundle

Bundle to save the Action.

@NonNull String key

Key used to save the Action.

setChecked

Added in 1.1.0
public void setChecked(boolean checked)

Sets whether this action is checked.

Parameters
boolean checked

Whether this action should be checked.

setDescription

Added in 1.1.0
public void setDescription(@Nullable CharSequence description)

Sets the description of this action.

Parameters
@Nullable CharSequence description

The description of the action.

setEditDescription

Added in 1.1.0
public void setEditDescription(@Nullable CharSequence editDescription)

Sets the optional description text to edit instead of setDescription.

Parameters
@Nullable CharSequence editDescription

Optional description text to edit instead of setDescription.

setEditTitle

Added in 1.1.0
public void setEditTitle(@Nullable CharSequence editTitle)

Sets the optional title text to edit instead of setTitle.

Parameters
@Nullable CharSequence editTitle

Optional title text to edit instead of setTitle.

setEnabled

Added in 1.1.0
public void setEnabled(boolean enabled)

Sets whether this action is enabled.

Parameters
boolean enabled

Whether this action should be enabled.

setFocusable

Added in 1.1.0
public void setFocusable(boolean focusable)

Sets whether this action is focusable.

Parameters
boolean focusable

Whether this action should be focusable.

setIntent

Added in 1.1.0
public void setIntent(@Nullable Intent intent)

Sets the intent of this action.

Parameters
@Nullable Intent intent

New intent to set on this action.

setSubActions

Added in 1.1.0
public void setSubActions(@Nullable List<GuidedAction> actions)

Change sub actions list.

Parameters
@Nullable List<GuidedAction> actions

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

setTitle

Added in 1.1.0
public void setTitle(@Nullable CharSequence title)

Sets the title of this action.

Parameters
@Nullable CharSequence title

The title set when this action was built.