public class

SegmentedButtonGroup

extends LinearLayout
java.lang.Object
   ↳ android.view.View
     ↳ android.view.ViewGroup
       ↳ android.widget.LinearLayout
         ↳ com.droidux.pack.action.widget.SegmentedButtonGroup

Class Overview

This widget represents a set of segments/buttons which is used to create a multiple-exclusion scope. Selecting one segmented button that belongs to a segmented button group unselects any previously selected segmented button within the same group. It is useful for example if you want to display alternative sets of data on the same view. The user can choose which set of data to display by selecting the appropriate segment/button.

See Also

Summary

Nested Classes
class SegmentedButtonGroup.LayoutParams

This set of layout parameters defaults the width and the height of the children to WRAP_CONTENT when they are not specified in the XML file. 

interface SegmentedButtonGroup.OnCheckedChangeListener

Interface definition for a callback to be invoked when the checked segmented button changed in this group. 

XML Attributes
Attribute Name Related Method Description
dux_color setColorStates(ColorStateList) Specifies a color. 
dux_segmentMode Controls whether to segment button should show text only, image only, or both. 
dux_segmentedBackground_first Reference to a drawable resource for use as the background of the first segment of a com.droidux.widget.tabs.SegmentedButtonGroup. 
dux_segmentedBackground_last Reference to a drawable resource for use as the background of the last segment of a com.droidux.widget.tabs.SegmentedButtonGroup. 
dux_segmentedBackground_middle Reference to a drawable resource for use as the background of the middle segment(s) of a com.droidux.widget.tabs.SegmentedButtonGroup. 
dux_segmentedBackground_single Reference to a drawable resource for use as the background of a single segment of a com.droidux.widget.tabs.SegmentedButtonGroup. 
[Expand]
Inherited Constants
From class android.widget.LinearLayout
From class android.view.ViewGroup
From class android.view.View
[Expand]
Inherited Fields
From class android.view.View
Public Constructors
SegmentedButtonGroup(Context context)
SegmentedButtonGroup(Context context, AttributeSet attrs)
Public Methods
void addView(View child, int index, ViewGroup.LayoutParams params)
Adds a child view with the specified layout parameters.
ActionInterfaces.Layout.ActionLayoutInterface beginLayout()
void check(ActionInterfaces.Item.ActionItem action)

Sets the selection to the segmented button whose action is passed in parameter.

void clearCheck()

Clears the selection.

SegmentedButtonGroup.LayoutParams generateLayoutParams(AttributeSet attrs)
Returns a new set of layout parameters based on the supplied attributes set.
View getActionView(ActionInterfaces.Item.ActionItem action)
Gets the View representing the specified action.
ActionInterfaces.Item.ActionItem getCheckedSegmentedButtonAction()

Returns the ActionInterfaces.Item.ActionItem associated with selected segmented butotn in this group.

void onEndLayout(ActionInterfaces.Layout.ActionLayoutInterface layout)
void setButtonBackgroundResources(int firstButton, int middleButton, int lastButton, int singleButton)
Sets the background drawables of the segmented buttons.
void setColorStates(ColorStateList colors)
Colorize the background with the specified tint color.
void setOnCheckedChangeListener(SegmentedButtonGroup.OnCheckedChangeListener listener)

Register a callback to be invoked when the selected segmented button changes in this group.

void setShouldCallbackOnUncheck(boolean callback)
Sets whether a callback should be made when the segmented button is uncheck.
Protected Methods
boolean checkLayoutParams(ViewGroup.LayoutParams p)
LinearLayout.LayoutParams generateDefaultLayoutParams()
Returns a set of layout parameters with a width of MATCH_PARENT and a height of WRAP_CONTENT when the layout's orientation is VERTICAL.
[Expand]
Inherited Methods
From class android.widget.LinearLayout
From class android.view.ViewGroup
From class android.view.View
From class java.lang.Object
From interface android.graphics.drawable.Drawable.Callback
From interface android.view.KeyEvent.Callback
From interface android.view.ViewManager
From interface android.view.ViewParent
From interface android.view.accessibility.AccessibilityEventSource

XML Attributes

dux_color

Since: API Level

Specifies a color.

May be a reference to another resource, in the form "@[+][package:]type:name" or to a theme attribute in the form "?[package:][type:]name".

May be a color value, in the form of "#rgb", "#argb", "#rrggbb", or "#aarrggbb".

dux_segmentMode

Since: API Level

Controls whether to segment button should show text only, image only, or both.

Must be one of the following constant values.

ConstantValueDescription
auto0 Automatically determined.
text1 Display the text only.
image2 Display the image only.

Related Methods

dux_segmentedBackground_first

Since: API Level

Reference to a drawable resource for use as the background of the first segment of a com.droidux.widget.tabs.SegmentedButtonGroup.

Must be a reference to another resource, in the form "@[+][package:]type:name" or to a theme attribute in the form "?[package:][type:]name".

Related Methods

dux_segmentedBackground_last

Since: API Level

Reference to a drawable resource for use as the background of the last segment of a com.droidux.widget.tabs.SegmentedButtonGroup.

Must be a reference to another resource, in the form "@[+][package:]type:name" or to a theme attribute in the form "?[package:][type:]name".

Related Methods

dux_segmentedBackground_middle

Since: API Level

Reference to a drawable resource for use as the background of the middle segment(s) of a com.droidux.widget.tabs.SegmentedButtonGroup.

Must be a reference to another resource, in the form "@[+][package:]type:name" or to a theme attribute in the form "?[package:][type:]name".

Related Methods

dux_segmentedBackground_single

Since: API Level

Reference to a drawable resource for use as the background of a single segment of a com.droidux.widget.tabs.SegmentedButtonGroup.

Must be a reference to another resource, in the form "@[+][package:]type:name" or to a theme attribute in the form "?[package:][type:]name".

Related Methods

Public Constructors

public SegmentedButtonGroup (Context context)

Since: API Level 2.5

public SegmentedButtonGroup (Context context, AttributeSet attrs)

Since: API Level 2.5

Public Methods

public void addView (View child, int index, ViewGroup.LayoutParams params)

Since: API Level

Adds a child view with the specified layout parameters.

Note: do not invoke this method from draw(android.graphics.Canvas), onDraw(android.graphics.Canvas), dispatchDraw(android.graphics.Canvas) or any related method.

Parameters
child the child view to add
index the position at which to add the child
params the layout parameters to set on the child

public void check (ActionInterfaces.Item.ActionItem action)

Since: API Level 2.5

Sets the selection to the segmented button whose action is passed in parameter. Using null as the selection identifier clears the selection; such an operation is equivalent to invoking clearCheck().

Parameters
action The action of the target radio button.

public void clearCheck ()

Since: API Level 2.5

Clears the selection. When the selection is cleared, no radio button in this group is selected and getCheckedSegmentedButtonAction() returns null.

public SegmentedButtonGroup.LayoutParams generateLayoutParams (AttributeSet attrs)

Since: API Level

Returns a new set of layout parameters based on the supplied attributes set.

Parameters
attrs the attributes to build the layout parameters from
Returns

public View getActionView (ActionInterfaces.Item.ActionItem action)

Since: API Level 2.5

Gets the View representing the specified action.

Parameters
action The action represented by the returned View.
Returns
  • Returns the View representing the specified action, or null if the action does not have associated view contained by this application bar.

public ActionInterfaces.Item.ActionItem getCheckedSegmentedButtonAction ()

Since: API Level 2.5

Returns the ActionInterfaces.Item.ActionItem associated with selected segmented butotn in this group. Upon empty selection, the returned value is null.

Returns

public void onEndLayout (ActionInterfaces.Layout.ActionLayoutInterface layout)

Since: API Level 2.5

public void setButtonBackgroundResources (int firstButton, int middleButton, int lastButton, int singleButton)

Since: API Level 2.5

Sets the background drawables of the segmented buttons.

Parameters
firstButton Background of the first button.
middleButton Background of the middle button(s).
lastButton Background of the last button.
singleButton Background of single button (in very rare situation, there might be only one button in the group).

public void setColorStates (ColorStateList colors)

Since: API Level 2.5

Colorize the background with the specified tint color. Tips: for better result, use a grayscale background.

Related XML Attributes
Parameters
colors The button's background tint.

public void setOnCheckedChangeListener (SegmentedButtonGroup.OnCheckedChangeListener listener)

Since: API Level 2.5

Register a callback to be invoked when the selected segmented button changes in this group.

Parameters
listener the callback to call on checked state change

public void setShouldCallbackOnUncheck (boolean callback)

Since: API Level 2.5

Sets whether a callback should be made when the segmented button is uncheck. By default, only when the segmented button is checked a callback to the listener will be made. If you need to perform action when the segmented button is unchecked, you need to pass true as the argument to this method.

Parameters
callback Whether to call back.

Protected Methods

protected boolean checkLayoutParams (ViewGroup.LayoutParams p)

Since: API Level

protected LinearLayout.LayoutParams generateDefaultLayoutParams ()

Since: API Level

Returns a set of layout parameters with a width of MATCH_PARENT and a height of WRAP_CONTENT when the layout's orientation is VERTICAL. When the orientation is HORIZONTAL, the width is set to WRAP_CONTENT and the height to WRAP_CONTENT.

Returns
  • a set of default layout parameters or null