Class TabHost

  • All Implemented Interfaces:
    FocusContainer

    public final class TabHost
    extends Section
    implements FocusContainer
    A tab container that renders the active tab's content plus a one-row tab bar. Children are retained across switches with only the visibility lifecycle firing, and the active content receives keys before the host's LEFT/RIGHT/CTRL_TAB switching.
    • Constructor Summary

      Constructors 
      Constructor Description
      TabHost()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int active()  
      Section activeFocusTarget()
      Returns the currently focused internal target.
      TabHost add​(java.lang.String title, Section content)
      Adds a tab with the given title and content.
      boolean advanceFocus​(boolean forward)
      Moves internal focus in the given direction.
      int count()  
      java.util.List<Section> focusTargets()
      Returns the focusable descendants this container manages internally.
      void select​(int index)
      Switches to the tab at the given index, firing the visibility lifecycle on the outgoing and incoming children.
      void select​(java.lang.String title)
      Switches to the tab with the given title.
      TabHost showTabBar​(boolean show)
      Sets whether the tab bar is shown.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • TabHost

        public TabHost()
    • Method Detail

      • add

        public TabHost add​(java.lang.String title,
                           Section content)
        Adds a tab with the given title and content.
        Parameters:
        title - the tab title
        content - the tab content section
        Returns:
        this TabHost for chaining
      • showTabBar

        public TabHost showTabBar​(boolean show)
        Sets whether the tab bar is shown.
        Parameters:
        show - true to show the tab bar
        Returns:
        this TabHost for chaining
      • active

        public int active()
        Returns:
        the active tab index
      • count

        public int count()
        Returns:
        the tab count
      • select

        public void select​(int index)
        Switches to the tab at the given index, firing the visibility lifecycle on the outgoing and incoming children. Out-of-range indices and the already-active index are ignored.
        Parameters:
        index - the tab index to activate
      • select

        public void select​(java.lang.String title)
        Switches to the tab with the given title. Unknown titles are ignored.
        Parameters:
        title - the tab title to activate
      • focusTargets

        public java.util.List<Section> focusTargets()
        Description copied from interface: FocusContainer
        Returns the focusable descendants this container manages internally.
        Specified by:
        focusTargets in interface FocusContainer
        Returns:
        the focus targets, in traversal order
      • activeFocusTarget

        public Section activeFocusTarget()
        Description copied from interface: FocusContainer
        Returns the currently focused internal target.
        Specified by:
        activeFocusTarget in interface FocusContainer
        Returns:
        the active focus target, or null when none is focused
      • advanceFocus

        public boolean advanceFocus​(boolean forward)
        Description copied from interface: FocusContainer
        Moves internal focus in the given direction.
        Specified by:
        advanceFocus in interface FocusContainer
        Parameters:
        forward - true to advance, false to move back
        Returns:
        true when focus moved internally, false at an edge so the parent advances instead