Added in API level 1

ExpandableListView


open class ExpandableListView : ListView
kotlin.Any
   ↳ android.view.View
   ↳ android.view.ViewGroup
   ↳ android.widget.AdapterView<android.widget.ListAdapter>
   ↳ 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(android.graphics.drawable.Drawable) or setGroupIndicator(android.graphics.drawable.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 ExpandableListContextMenuInfo object with ExpandableListContextMenuInfo#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.

Summary

Nested classes
open

Extra menu information specific to an ExpandableListView provided to the android.view.View.OnCreateContextMenuListener#onCreateContextMenu(ContextMenu, View, ContextMenuInfo) callback when a context menu is brought up for this AdapterView.

abstract

Interface definition for a callback to be invoked when a child in this expandable list has been clicked.

abstract

Interface definition for a callback to be invoked when a group in this expandable list has been clicked.

abstract

Used for being notified when a group is collapsed

abstract

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:childIndicatorEnd The end bound for a child's indicator.
android:childIndicatorLeft The left bound for a child's indicator.
android:childIndicatorRight The right bound for a child's indicator.
android:childIndicatorStart The start bound for a child's indicator.
android:groupIndicator Indicator shown beside the group View.
android:indicatorEnd The end bound for an item's indicator.
android:indicatorLeft The left bound for an item's indicator.
android:indicatorRight The right bound for an item's indicator.
android:indicatorStart The start bound for an item's indicator.
Inherited XML attributes
Constants
static Int

Denotes when a child indicator should inherit this bound from the generic indicator bounds

static Int

The packed position represents a child.

static Int

The packed position represents a group.

static Int

The packed position represents a neither/null/no preference.

static Long

The value for a packed position that represents neither/null/no preference.

Inherited constants
Public constructors

ExpandableListView(context: Context!, attrs: AttributeSet!, defStyleAttr: Int)

ExpandableListView(context: Context!, attrs: AttributeSet!, defStyleAttr: Int, defStyleRes: Int)

Public methods
open Boolean
collapseGroup(groupPos: Int)

Collapse a group in the grouped list view

open Boolean
expandGroup(groupPos: Int)

Expand a group in the grouped list view

open Boolean
expandGroup(groupPos: Int, animate: Boolean)

Expand a group in the grouped list view

open CharSequence!

open ListAdapter!

This method should not be used, use getExpandableListAdapter().

open ExpandableListAdapter!

Gets the adapter that provides data to this view.

open Long
getExpandableListPosition(flatListPosition: Int)

Converts a flat list position (the raw position of an item (child or group) in the list) to a group and/or child position (represented in a packed position).

open Int
getFlatListPosition(packedPosition: Long)

Converts a group and/or child position to a flat list position.

open static Int
getPackedPositionChild(packedPosition: Long)

Gets the child position from a packed position that is of PACKED_POSITION_TYPE_CHILD type (use getPackedPositionType(long)).

open static Long
getPackedPositionForChild(groupPosition: Int, childPosition: Int)

Returns the packed position representation of a child's position.

open static Long

Returns the packed position representation of a group's position.

open static Int
getPackedPositionGroup(packedPosition: Long)

Gets the group position from a packed position.

open static Int
getPackedPositionType(packedPosition: Long)

Gets the type of a packed position.

open Long

Gets the ID of the currently selected group or child.

open Long

Gets the position of the currently selected group or child (along with its type).

open Boolean
isGroupExpanded(groupPosition: Int)

Whether the given group is currently expanded.

open Unit

open Unit
onRtlPropertiesChanged(layoutDirection: Int)

open Parcelable?

open Boolean
performItemClick(v: View!, position: Int, id: Long)

open Unit

This overloaded method should not be used, instead use setAdapter(android.widget.ExpandableListAdapter).

open Unit

Sets the adapter that provides data to this view.

open Unit
setChildDivider(childDivider: Drawable!)

Sets the drawable that will be drawn adjacent to every child in the list.

open Unit
setChildIndicator(childIndicator: Drawable!)

Sets the indicator to be drawn next to a child.

open Unit

Sets the drawing bounds for the child indicator.

open Unit

Sets the relative drawing bounds for the child indicator.

open Unit
setGroupIndicator(groupIndicator: Drawable!)

Sets the indicator to be drawn next to a group.

open Unit
setIndicatorBounds(left: Int, right: Int)

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).

open Unit

Sets the relative 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).

open Unit

open Unit

open Unit

open Unit

open Unit

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.

open Boolean
setSelectedChild(groupPosition: Int, childPosition: Int, shouldExpandGroup: Boolean)

Sets the selection to the specified child.

open Unit
setSelectedGroup(groupPosition: Int)

Sets the selection to the specified group.

Protected methods
open Unit

Inherited functions
Inherited properties

XML attributes

android:childDivider

android:childDivider
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 a theme attribute in the form "?[package:]type/name".

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

android:childIndicator

android:childIndicator
Indicator shown beside the child View. This can be a stateful Drawable.

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

android:childIndicatorEnd

android:childIndicatorEnd
The end bound for a child's indicator.

May 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), and mm (millimeters).

android:childIndicatorLeft

android:childIndicatorLeft
The left bound for a child's indicator.

May 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), and mm (millimeters).

android:childIndicatorRight

android:childIndicatorRight
The right bound for a child's indicator.

May 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), and mm (millimeters).

android:childIndicatorStart

android:childIndicatorStart
The start bound for a child's indicator.

May 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), and mm (millimeters).

android:groupIndicator

android:groupIndicator
Indicator shown beside the group View. This can be a stateful Drawable.

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

android:indicatorEnd

android:indicatorEnd
The end bound for an item's indicator. To specify a right bound specific to children, use childIndicatorEnd.

May 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), and mm (millimeters).

android:indicatorLeft

android:indicatorLeft
The left bound for an item's indicator. To specify a left bound specific to children, use childIndicatorLeft.

May 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), and mm (millimeters).

android:indicatorRight

android:indicatorRight
The right bound for an item's indicator. To specify a right bound specific to children, use childIndicatorRight.

May 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), and mm (millimeters).

android:indicatorStart

android:indicatorStart
The start bound for an item's indicator. To specify a start bound specific to children, use childIndicatorStart.

May 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), and mm (millimeters).

Constants

CHILD_INDICATOR_INHERIT

Added in API level 1
static val CHILD_INDICATOR_INHERIT: Int

Denotes when a child indicator should inherit this bound from the generic indicator bounds

Value: -1

PACKED_POSITION_TYPE_CHILD

Added in API level 1
static val PACKED_POSITION_TYPE_CHILD: Int

The packed position represents a child.

Value: 1

PACKED_POSITION_TYPE_GROUP

Added in API level 1
static val PACKED_POSITION_TYPE_GROUP: Int

The packed position represents a group.

Value: 0

PACKED_POSITION_TYPE_NULL

Added in API level 1
static val PACKED_POSITION_TYPE_NULL: Int

The packed position represents a neither/null/no preference.

Value: 2

PACKED_POSITION_VALUE_NULL

Added in API level 1
static val PACKED_POSITION_VALUE_NULL: Long

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.

Value: 4294967295L

Public constructors

ExpandableListView

Added in API level 1
ExpandableListView(context: Context!)

ExpandableListView

Added in API level 1
ExpandableListView(
    context: Context!,
    attrs: AttributeSet!)

ExpandableListView

Added in API level 1
ExpandableListView(
    context: Context!,
    attrs: AttributeSet!,
    defStyleAttr: Int)

ExpandableListView

Added in API level 21
ExpandableListView(
    context: Context!,
    attrs: AttributeSet!,
    defStyleAttr: Int,
    defStyleRes: Int)

Public methods

collapseGroup

Added in API level 1
open fun collapseGroup(groupPos: Int): Boolean

Collapse a group in the grouped list view

Parameters
groupPos Int: position of the group to collapse
Return
Boolean True if the group was collapsed, false otherwise (if the group was already collapsed, this will return false)

expandGroup

Added in API level 1
open fun expandGroup(groupPos: Int): Boolean

Expand a group in the grouped list view

Parameters
groupPos Int: the group to be expanded
Return
Boolean True if the group was expanded, false otherwise (if the group was already expanded, this will return false)

expandGroup

Added in API level 14
open fun expandGroup(
    groupPos: Int,
    animate: Boolean
): Boolean

Expand a group in the grouped list view

Parameters
groupPos Int: the group to be expanded
animate Boolean: true if the expanding group should be animated in
Return
Boolean True if the group was expanded, false otherwise (if the group was already expanded, this will return false)

getAccessibilityClassName

Added in API level 23
open fun getAccessibilityClassName(): CharSequence!

getAdapter

Added in API level 1
open fun getAdapter(): ListAdapter!

This method should not be used, use getExpandableListAdapter().

Return
ListAdapter! The adapter currently used to display data in this ListView.

getExpandableListAdapter

Added in API level 1
open fun getExpandableListAdapter(): ExpandableListAdapter!

Gets the adapter that provides data to this view.

Return
ExpandableListAdapter! The adapter that provides data to this view.

getExpandableListPosition

Added in API level 1
open fun getExpandableListPosition(flatListPosition: Int): Long

Converts a flat list position (the raw position of an item (child or group) in the list) to a 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 ExpandableListView#getPackedPositionType , ExpandableListView#getPackedPositionChild, ExpandableListView#getPackedPositionGroup to unpack.

Parameters
flatListPosition Int: The flat list position to be converted.
Return
Long The group and/or child position for the given flat list position in packed position representation. #PACKED_POSITION_VALUE_NULL if the position corresponds to a header or a footer item.

getFlatListPosition

Added in API level 1
open fun getFlatListPosition(packedPosition: Long): Int

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.

Parameters
packedPosition Long: The group and/or child positions to be converted in packed position representation. Use getPackedPositionForChild(int,int) or getPackedPositionForGroup(int).
Return
Int The flat list position for the given child or group.

getPackedPositionChild

Added in API level 1
open static fun getPackedPositionChild(packedPosition: Long): 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).

Parameters
packedPosition Long: The packed position from which the child position will be returned.
Return
Int The child position portion of the packed position. If this does not contain a child, returns -1.

getPackedPositionForChild

Added in API level 1
open static fun getPackedPositionForChild(
    groupPosition: Int,
    childPosition: Int
): Long

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).

Parameters
groupPosition Int: The child's parent group's position.
childPosition Int: The child position within the group.
Return
Long The packed position representation of the child (and parent group).

getPackedPositionForGroup

Added in API level 1
open static fun getPackedPositionForGroup(groupPosition: Int): Long

Returns the packed position representation of a group's position. See getPackedPositionForChild(int,int).

Parameters
groupPosition Int: The child's parent group's position.
Return
Long The packed position representation of the group.

getPackedPositionGroup

Added in API level 1
open static fun getPackedPositionGroup(packedPosition: Long): Int

Gets the group position from a packed position. See getPackedPositionForChild(int,int).

Parameters
packedPosition Long: The packed position from which the group position will be returned.
Return
Int The group position portion of the packed position. If this does not contain a group, returns -1.

getPackedPositionType

Added in API level 1
open static fun getPackedPositionType(packedPosition: Long): Int

Gets the type of a packed position. See getPackedPositionForChild(int,int).

Parameters
packedPosition Long: The packed position for which to return the type.
Return
Int The type of the position contained within the packed position, either PACKED_POSITION_TYPE_CHILD, PACKED_POSITION_TYPE_GROUP, or PACKED_POSITION_TYPE_NULL.

getSelectedId

Added in API level 1
open fun getSelectedId(): Long

Gets the ID of the currently selected group or child. Can return -1 if no selection.

Return
Long The ID of the currently selected group or child. -1 if no selection.

getSelectedPosition

Added in API level 1
open fun getSelectedPosition(): Long

Gets the position of the currently selected group or child (along with its type). Can return PACKED_POSITION_VALUE_NULL if no selection.

Return
Long A packed position containing the currently selected group or child's position and type. #PACKED_POSITION_VALUE_NULL if no selection or if selection is on a header or a footer item.

isGroupExpanded

Added in API level 1
open fun isGroupExpanded(groupPosition: Int): Boolean

Whether the given group is currently expanded.

Parameters
groupPosition Int: The group to check.
Return
Boolean Whether the group is currently expanded.

onRestoreInstanceState

Added in API level 1
open fun onRestoreInstanceState(state: Parcelable!): Unit
Parameters
state Parcelable!: The frozen state that had previously been returned by onSaveInstanceState.

onRtlPropertiesChanged

Added in API level 17
open fun onRtlPropertiesChanged(layoutDirection: Int): Unit
Parameters
layoutDirection Int: the direction of the layout Value is android.view.View#LAYOUT_DIRECTION_LTR, or android.view.View#LAYOUT_DIRECTION_RTL

onSaveInstanceState

Added in API level 1
open fun onSaveInstanceState(): Parcelable?
Return
Parcelable? Returns a Parcelable object containing the view's current dynamic state, or null if there is nothing interesting to save.

performItemClick

Added in API level 1
open fun performItemClick(
    v: View!,
    position: Int,
    id: Long
): Boolean
Parameters
view The view within the AdapterView that was clicked.
position Int: The position of the view in the adapter.
id Long: The row id of the item that was clicked.
Return
Boolean True if there was an assigned OnItemClickListener that was called, false otherwise is returned.

setAdapter

Added in API level 1
open fun setAdapter(adapter: ListAdapter!): Unit

This overloaded method should not be used, instead use setAdapter(android.widget.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.

Parameters
adapter ListAdapter!: 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.

setAdapter

Added in API level 1
open fun setAdapter(adapter: ExpandableListAdapter!): Unit

Sets the adapter that provides data to this view.

Parameters
adapter ExpandableListAdapter!: The adapter that provides data to this view.

setChildDivider

Added in API level 1
open fun setChildDivider(childDivider: Drawable!): Unit

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(android.graphics.drawable.Drawable)) or if it does not have an intrinsic height, the height set by setDividerHeight(int).

Parameters
childDivider Drawable!: The drawable to use.

setChildIndicator

Added in API level 1
open fun setChildIndicator(childIndicator: Drawable!): Unit

Sets the indicator to be drawn next to a child.

Parameters
childIndicator Drawable!: The drawable to be used as an indicator. If the child is the last child for a group, the state android.R.attr#state_last will be set.

setChildIndicatorBounds

Added in API level 1
open fun setChildIndicatorBounds(
    left: Int,
    right: Int
): Unit

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.

Parameters
left Int: The left position (relative to the left bounds of this View) to start drawing the indicator.
right Int: The right position (relative to the left bounds of this View) to end the drawing of the indicator.

setChildIndicatorBoundsRelative

Added in API level 18
open fun setChildIndicatorBoundsRelative(
    start: Int,
    end: Int
): Unit

Sets the relative drawing bounds for the child indicator. For either, you can specify CHILD_INDICATOR_INHERIT to use inherit from the general indicator's bounds.

Parameters
start Int: The start position (relative to the start bounds of this View) to start drawing the indicator.
end Int: The end position (relative to the end bounds of this View) to end the drawing of the indicator.

setGroupIndicator

Added in API level 1
open fun setGroupIndicator(groupIndicator: Drawable!): Unit

Sets the indicator to be drawn next to a group.

Parameters
groupIndicator Drawable!: The drawable to be used as an indicator. If the group is empty, the state android.R.attr#state_empty will be set. If the group is expanded, the state android.R.attr#state_expanded will be set.

setIndicatorBounds

Added in API level 1
open fun setIndicatorBounds(
    left: Int,
    right: Int
): Unit

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).

Parameters
left Int: The left position (relative to the left bounds of this View) to start drawing the indicator.
right Int: The right position (relative to the left bounds of this View) to end the drawing of the indicator.

setIndicatorBoundsRelative

Added in API level 18
open fun setIndicatorBoundsRelative(
    start: Int,
    end: Int
): Unit

Sets the relative 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).

Parameters
start Int: The start position (relative to the start bounds of this View) to start drawing the indicator.
end Int: The end position (relative to the end bounds of this View) to end the drawing of the indicator.

setOnChildClickListener

Added in API level 1
open fun setOnChildClickListener(onChildClickListener: ExpandableListView.OnChildClickListener!): Unit

setOnGroupClickListener

Added in API level 1
open fun setOnGroupClickListener(onGroupClickListener: ExpandableListView.OnGroupClickListener!): Unit

setOnGroupCollapseListener

Added in API level 1
open fun setOnGroupCollapseListener(onGroupCollapseListener: ExpandableListView.OnGroupCollapseListener!): Unit

setOnGroupExpandListener

Added in API level 1
open fun setOnGroupExpandListener(onGroupExpandListener: ExpandableListView.OnGroupExpandListener!): Unit

setOnItemClickListener

Added in API level 1
open fun setOnItemClickListener(l: AdapterView.OnItemClickListener?): Unit

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 and/or setOnChildClickListener.

Register a callback to be invoked when an item in this AdapterView has been clicked.
Parameters
listener The callback that will be invoked. This value may be null.

setSelectedChild

Added in API level 1
open fun setSelectedChild(
    groupPosition: Int,
    childPosition: Int,
    shouldExpandGroup: Boolean
): Boolean

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.

Parameters
groupPosition Int: The position of the group that contains the child.
childPosition Int: The position of the child within the group.
shouldExpandGroup Boolean: Whether the child's group should be expanded if it is collapsed.
Return
Boolean Whether the selection was successfully set on the child.

setSelectedGroup

Added in API level 1
open fun setSelectedGroup(groupPosition: Int): Unit

Sets the selection to the specified group.

Parameters
groupPosition Int: The position of the group that should be selected.

Protected methods

dispatchDraw

Added in API level 1
protected open fun dispatchDraw(canvas: Canvas): Unit
Parameters
canvas Canvas: This value cannot be null.