java.lang.Object | ||||||
↳ | android.view.View | |||||
↳ | android.view.ViewGroup | |||||
↳ | android.widget.AdapterView<T extends android.widget.Adapter> | |||||
↳ | android.widget.AbsListView | |||||
↳ | android.widget.ListView | |||||
↳ | android.widget.ExpandableListView |
A view that shows items in a vertically scrolling two-level list. This differs from the ListView by allowing two levels: groups which can individually be expanded to show its children. The items come from the ExpandableListAdapter associated with this view.
Expandable lists are able to show an indicator beside each item to display the item's current state (the states are usually one of expanded group, collapsed group, child, or last child). Use setChildIndicator(Drawable) or setGroupIndicator(Drawable) (or the corresponding XML attributes) to set these indicators (see the docs for each method to see additional state that each Drawable can have). The default style for an ExpandableListView provides indicators which will be shown next to Views given to the ExpandableListView. The layouts android.R.layout.simple_expandable_list_item_1 and android.R.layout.simple_expandable_list_item_2 (which should be used with SimpleCursorTreeAdapter) contain the preferred position information for indicators.
The context menu information set by an ExpandableListView will be a ExpandableListView.ExpandableListContextMenuInfo object with packedPosition being a packed position that can be used with getPackedPositionType(long) and the other similar methods.
Note: You cannot use the value wrap_content
for the android:layout_height
attribute of a
ExpandableListView in XML if the parent's size is also not strictly specified
(for example, if the parent were ScrollView you could not specify
wrap_content since it also can be any length. However, you can use
wrap_content if the ExpandableListView parent has a specific size, such as
100 pixels.
Nested Classes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
ExpandableListView.ExpandableListContextMenuInfo | Extra menu information specific to an ExpandableListView provided to the onCreateContextMenu(ContextMenu, View, ContextMenuInfo) callback when a context menu is brought up for this AdapterView. | ||||||||||
ExpandableListView.OnChildClickListener | Interface definition for a callback to be invoked when a child in this expandable list has been clicked. | ||||||||||
ExpandableListView.OnGroupClickListener | Interface definition for a callback to be invoked when a group in this expandable list has been clicked. | ||||||||||
ExpandableListView.OnGroupCollapseListener | Used for being notified when a group is collapsed | ||||||||||
ExpandableListView.OnGroupExpandListener | Used for being notified when a group is expanded |
XML Attributes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
android:childDivider | Drawable or color that is used as a divider for children. | ||||||||||
android:childIndicator | Indicator shown beside the child View. | ||||||||||
android:childIndicatorLeft | The left bound for a child's indicator. | ||||||||||
android:childIndicatorRight | The right bound for a child's indicator. | ||||||||||
android:groupIndicator | Indicator shown beside the group View. | ||||||||||
android:indicatorLeft | The left bound for an item's indicator. | ||||||||||
android:indicatorRight | The right bound for an item's indicator. |
[Expand]
Inherited XML Attributes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
android.widget.ListView
| |||||||||||
From class
android.widget.AbsListView
| |||||||||||
From class
android.view.ViewGroup
| |||||||||||
From class
android.view.View
|
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
int | CHILD_INDICATOR_INHERIT | Denotes when a child indicator should inherit this bound from the generic indicator bounds | |||||||||
int | PACKED_POSITION_TYPE_CHILD | The packed position represents a child. | |||||||||
int | PACKED_POSITION_TYPE_GROUP | The packed position represents a group. | |||||||||
int | PACKED_POSITION_TYPE_NULL | The packed position represents a neither/null/no preference. | |||||||||
long | PACKED_POSITION_VALUE_NULL | The value for a packed position that represents neither/null/no preference. |
[Expand]
Inherited Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
android.widget.ListView
| |||||||||||
From class
android.widget.AbsListView
| |||||||||||
From class
android.widget.AdapterView
| |||||||||||
From class
android.view.ViewGroup
| |||||||||||
From class
android.view.View
|
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Collapse a group in the grouped list view
| |||||||||||
Expand a group in the grouped list view
| |||||||||||
This method should not be used, use getExpandableListAdapter().
| |||||||||||
Gets the adapter that provides data to this view.
| |||||||||||
Converts a flat list position (the raw position of an item (child or
group) in the list) to an group and/or child position (represented in a
packed position).
| |||||||||||
Converts a group and/or child position to a flat list position.
| |||||||||||
Gets the child position from a packed position that is of
PACKED_POSITION_TYPE_CHILD type (use getPackedPositionType(long)).
| |||||||||||
Returns the packed position representation of a child's position.
| |||||||||||
Returns the packed position representation of a group's position.
| |||||||||||
Gets the group position from a packed position.
| |||||||||||
Gets the type of a packed position.
| |||||||||||
Gets the ID of the currently selected group or child.
| |||||||||||
Gets the position of the currently selected group or child (along with
its type).
| |||||||||||
Whether the given group is currently expanded.
| |||||||||||
Hook allowing a view to re-apply a representation of its internal state that had previously
been generated by onSaveInstanceState().
| |||||||||||
Hook allowing a view to generate a representation of its internal state
that can later be used to create a new instance with that same state.
| |||||||||||
Call the OnItemClickListener, if it is defined.
| |||||||||||
Sets the adapter that provides data to this view.
| |||||||||||
This overloaded method should not be used, instead use
setAdapter(ExpandableListAdapter).
| |||||||||||
Sets the drawable that will be drawn adjacent to every child in the list.
| |||||||||||
Sets the indicator to be drawn next to a child.
| |||||||||||
Sets the drawing bounds for the child indicator.
| |||||||||||
Sets the indicator to be drawn next to a group.
| |||||||||||
Sets the drawing bounds for the indicators (at minimum, the group indicator
is affected by this; the child indicator is affected by this if the
child indicator bounds are set to inherit).
| |||||||||||
Register a callback to be invoked when an item has been clicked and the
caller prefers to receive a ListView-style position instead of a group
and/or child position.
| |||||||||||
Sets the selection to the specified child.
| |||||||||||
Sets the selection to the specified group.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Called by draw to draw the child views.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class android.widget.ListView
| |||||||||||
From class android.widget.AbsListView
| |||||||||||
From class android.widget.AdapterView
| |||||||||||
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.text.TextWatcher
| |||||||||||
From interface android.view.KeyEvent.Callback
| |||||||||||
From interface android.view.ViewManager
| |||||||||||
From interface android.view.ViewParent
| |||||||||||
From interface android.view.ViewTreeObserver.OnGlobalLayoutListener
| |||||||||||
From interface android.view.ViewTreeObserver.OnTouchModeChangeListener
| |||||||||||
From interface android.widget.Filter.FilterListener
|
Drawable or color that is used as a divider for children. (It will drawn below and above child items.) The height of this will be the same as the height of the normal list item divider.
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
".
This corresponds to the global attribute resource symbol childDivider.
Indicator shown beside the child View. This can be a stateful Drawable.
Must be a reference to another resource, in the form "@[+][package:]type:name
"
or to a theme attribute in the form "?[package:][type:]name
".
This corresponds to the global attribute resource symbol childIndicator.
The left bound for a child's indicator.
Must be a dimension value, which is a floating point number appended with a unit such as "14.5sp
".
Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size),
in (inches), mm (millimeters).
This may also be a reference to a resource (in the form
"@[package:]type:name
") or
theme attribute (in the form
"?[package:][type:]name
")
containing a value of this type.
This corresponds to the global attribute resource symbol childIndicatorLeft.
The right bound for a child's indicator.
Must be a dimension value, which is a floating point number appended with a unit such as "14.5sp
".
Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size),
in (inches), mm (millimeters).
This may also be a reference to a resource (in the form
"@[package:]type:name
") or
theme attribute (in the form
"?[package:][type:]name
")
containing a value of this type.
This corresponds to the global attribute resource symbol childIndicatorRight.
Indicator shown beside the group View. This can be a stateful Drawable.
Must be a reference to another resource, in the form "@[+][package:]type:name
"
or to a theme attribute in the form "?[package:][type:]name
".
This corresponds to the global attribute resource symbol groupIndicator.
The left bound for an item's indicator. To specify a left bound specific to children, use childIndicatorLeft.
Must be a dimension value, which is a floating point number appended with a unit such as "14.5sp
".
Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size),
in (inches), mm (millimeters).
This may also be a reference to a resource (in the form
"@[package:]type:name
") or
theme attribute (in the form
"?[package:][type:]name
")
containing a value of this type.
This corresponds to the global attribute resource symbol indicatorLeft.
The right bound for an item's indicator. To specify a right bound specific to children, use childIndicatorRight.
Must be a dimension value, which is a floating point number appended with a unit such as "14.5sp
".
Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size),
in (inches), mm (millimeters).
This may also be a reference to a resource (in the form
"@[package:]type:name
") or
theme attribute (in the form
"?[package:][type:]name
")
containing a value of this type.
This corresponds to the global attribute resource symbol indicatorRight.
Denotes when a child indicator should inherit this bound from the generic indicator bounds
The packed position represents a child.
The packed position represents a group.
The packed position represents a neither/null/no preference.
The value for a packed position that represents neither/null/no preference. This value is not otherwise possible since a group type (first bit 0) should not have a child position filled.
Collapse a group in the grouped list view
groupPos | position of the group to collapse |
---|
Expand a group in the grouped list view
groupPos | the group to be expanded |
---|
This method should not be used, use getExpandableListAdapter().
Gets the adapter that provides data to this view.
Converts a flat list position (the raw position of an item (child or group) in the list) to an group and/or child position (represented in a packed position). This is useful in situations where the caller needs to use the underlying ListView's methods. Use getPackedPositionType(long) , getPackedPositionChild(long), getPackedPositionGroup(long) to unpack.
flatListPosition | The flat list position to be converted. |
---|
Converts a group and/or child position to a flat list position. This is useful in situations where the caller needs to use the underlying ListView's methods.
packedPosition | The group and/or child positions to be converted in packed position representation. Use getPackedPositionForChild(int, int) or getPackedPositionForGroup(int). |
---|
Gets the child position from a packed position that is of PACKED_POSITION_TYPE_CHILD type (use getPackedPositionType(long)). To get the group that this child belongs to, use getPackedPositionGroup(long). See getPackedPositionForChild(int, int).
packedPosition | The packed position from which the child position will be returned. |
---|
Returns the packed position representation of a child's position.
In general, a packed position should be used in situations where the position given to/returned from an ExpandableListAdapter or ExpandableListView method can either be a child or group. The two positions are packed into a single long which can be unpacked using getPackedPositionChild(long), getPackedPositionGroup(long), and getPackedPositionType(long).
groupPosition | The child's parent group's position. |
---|---|
childPosition | The child position within the group. |
Returns the packed position representation of a group's position. See getPackedPositionForChild(int, int).
groupPosition | The child's parent group's position. |
---|
Gets the group position from a packed position. See getPackedPositionForChild(int, int).
packedPosition | The packed position from which the group position will be returned. |
---|
Gets the type of a packed position. See getPackedPositionForChild(int, int).
packedPosition | The packed position for which to return the type. |
---|
Gets the ID of the currently selected group or child. Can return -1 if no selection.
Gets the position of the currently selected group or child (along with its type). Can return PACKED_POSITION_VALUE_NULL if no selection.
Whether the given group is currently expanded.
groupPosition | The group to check. |
---|
Hook allowing a view to re-apply a representation of its internal state that had previously been generated by onSaveInstanceState(). This function will never be called with a null state.
state | The frozen state that had previously been returned by onSaveInstanceState(). |
---|
Hook allowing a view to generate a representation of its internal state that can later be used to create a new instance with that same state. This state should only contain information that is not persistent or can not be reconstructed later. For example, you will never store your current position on screen because that will be computed again when a new instance of the view is placed in its view hierarchy.
Some examples of things you may store here: the current cursor position in a text view (but usually not the text itself since that is stored in a content provider or other persistent storage), the currently selected item in a list view.
Call the OnItemClickListener, if it is defined.
v | The view within the AdapterView that was clicked. |
---|---|
position | The position of the view in the adapter. |
id | The row id of the item that was clicked. |
Sets the adapter that provides data to this view.
adapter | The adapter that provides data to this view. |
---|
This overloaded method should not be used, instead use setAdapter(ExpandableListAdapter).
Sets the data behind this ListView. The adapter passed to this method may be wrapped by a WrapperListAdapter, depending on the ListView features currently in use. For instance, adding headers and/or footers will cause the adapter to be wrapped.
adapter | The ListAdapter which is responsible for maintaining the data backing this list and for producing a view to represent an item in that data set. |
---|
Sets the drawable that will be drawn adjacent to every child in the list. This will be drawn using the same height as the normal divider (setDivider(Drawable)) or if it does not have an intrinsic height, the height set by setDividerHeight(int).
childDivider | The drawable to use. |
---|
Sets the indicator to be drawn next to a child.
childIndicator | The drawable to be used as an indicator. If the child is the last child for a group, the state state_last will be set. |
---|
Sets the drawing bounds for the child indicator. For either, you can specify CHILD_INDICATOR_INHERIT to use inherit from the general indicator's bounds.
left | The left position (relative to the left bounds of this View) to start drawing the indicator. |
---|---|
right | The right position (relative to the left bounds of this View) to end the drawing of the indicator. |
Sets the indicator to be drawn next to a group.
groupIndicator | The drawable to be used as an indicator. If the group is empty, the state state_empty will be set. If the group is expanded, the state state_expanded will be set. |
---|
Sets the drawing bounds for the indicators (at minimum, the group indicator is affected by this; the child indicator is affected by this if the child indicator bounds are set to inherit).
left | The left position (relative to the left bounds of this View) to start drawing the indicator. |
---|---|
right | The right position (relative to the left bounds of this View) to end the drawing of the indicator. |
Register a callback to be invoked when an item has been clicked and the caller prefers to receive a ListView-style position instead of a group and/or child position. In most cases, the caller should use setOnGroupClickListener(ExpandableListView.OnGroupClickListener) and/or setOnChildClickListener(ExpandableListView.OnChildClickListener).
Register a callback to be invoked when an item in this AdapterView has been clicked.l | The callback that will be invoked. |
---|
Sets the selection to the specified child. If the child is in a collapsed group, the group will only be expanded and child subsequently selected if shouldExpandGroup is set to true, otherwise the method will return false.
groupPosition | The position of the group that contains the child. |
---|---|
childPosition | The position of the child within the group. |
shouldExpandGroup | Whether the child's group should be expanded if it is collapsed. |
Sets the selection to the specified group.
groupPosition | The position of the group that should be selected. |
---|
Called by draw to draw the child views. This may be overridden by derived classes to gain control just before its children are drawn (but after its own view has been drawn).
canvas | the canvas on which to draw the view |
---|