android: what is the difference between focused, enabled, pressed, and selected states?

Enabled -> User Interaction possible.

Disabled -> User interaction not possible.

  • if you hover the mouse over a widget, it is focussed
  • If you make a press-down (half click) on that widget, it is pressed
  • If you press-down and press-up while the mouse is at the same position, it is selected

Focused - (Window, View) is a destination of keyboard events (yes, some Androids have physical keyboard) and some have "deodorant-ball" generating left up right down arrows keyboard shortcuts.

Activated - the widget (view) which is activated. E.g. in multi selection list the selected views are activated. I believe the necessity of this additional stage in API 11 was due to activating multi-selection that contains checkboxes. Thus the selected and checked states need to be separated.

Selected - is only applicable to check boxes and other selectable views.

The complete list of View states is (StateSet id on the left, flag on the right):

    R.attr.state_window_focused,    VIEW_STATE_WINDOW_FOCUSED,
    R.attr.state_selected,          VIEW_STATE_SELECTED,
    R.attr.state_focused,           VIEW_STATE_FOCUSED,
    R.attr.state_enabled,           VIEW_STATE_ENABLED,
    R.attr.state_pressed,           VIEW_STATE_PRESSED,
    R.attr.state_activated,         VIEW_STATE_ACTIVATED,
    R.attr.state_accelerated,       VIEW_STATE_ACCELERATED,
    R.attr.state_hovered,           VIEW_STATE_HOVERED,
    R.attr.state_drag_can_accept,   VIEW_STATE_DRAG_CAN_ACCEPT,
    R.attr.state_drag_hovered,      VIEW_STATE_DRAG_HOVERED

Also see:

/**
 * Changes the activated state of this view. A view can be activated or not.
 * Note that activation is not the same as selection.  Selection is
 * a transient property, representing the view (hierarchy) the user is
 * currently interacting with.  Activation is a longer-term state that the
 * user can move views in and out of.  For example, in a list view with
 * single or multiple selection enabled, the views in the current selection
 * set are activated.  (Um, yeah, we are deeply sorry about the terminology
 * here.)  The activated state is propagated down to children of the view it
 * is set on.
 *
 * @param activated true if the view must be activated, false otherwise
 */
public void setActivated(boolean activated)



/**
 * Dispatch a key event to the next view on the focus path. This path runs
 * from the top of the view tree down to the currently focused view. If this
 * view has focus, it will dispatch to itself. Otherwise it will dispatch
 * the next node down the focus path. This method also fires any key
 * listeners.
 *
 * @param event The key event to be dispatched.
 * @return True if the event was handled, false otherwise.
 */
public boolean dispatchKeyEvent(KeyEvent event)

Tags:

Android

View