|
Build 1.0_r1(from source) | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectandroid.view.View
android.view.ViewGroup
android.widget.AdapterView<ListAdapter>
android.widget.AbsListView
android.widget.ListView
android.widget.ExpandableListView
public class 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
ExpandableListView.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.
| Nested Class Summary | |
|---|---|
static class |
ExpandableListView.ExpandableListContextMenuInfo
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. |
static interface |
ExpandableListView.OnChildClickListener
Interface definition for a callback to be invoked when a child in this expandable list has been clicked. |
static interface |
ExpandableListView.OnGroupClickListener
Interface definition for a callback to be invoked when a group in this expandable list has been clicked. |
static interface |
ExpandableListView.OnGroupCollapseListener
Used for being notified when a group is collapsed |
static interface |
ExpandableListView.OnGroupExpandListener
Used for being notified when a group is expanded |
(package private) static class |
ExpandableListView.SavedState
|
| Nested classes/interfaces inherited from class android.widget.ListView |
|---|
ListView.FixedViewInfo |
| Nested classes/interfaces inherited from class android.widget.AbsListView |
|---|
AbsListView.CheckForTap, AbsListView.LayoutParams, AbsListView.OnScrollListener, AbsListView.RecycleBin, AbsListView.RecyclerListener |
| Nested classes/interfaces inherited from class android.widget.AdapterView |
|---|
AdapterView.AdapterContextMenuInfo, AdapterView.AdapterDataSetObserver, AdapterView.OnItemClickListener, AdapterView.OnItemLongClickListener, AdapterView.OnItemSelectedListener |
| Nested classes/interfaces inherited from class android.view.ViewGroup |
|---|
ViewGroup.MarginLayoutParams, ViewGroup.OnHierarchyChangeListener |
| Nested classes/interfaces inherited from class android.view.View |
|---|
View.BaseSavedState, View.MeasureSpec, View.OnClickListener, View.OnCreateContextMenuListener, View.OnFocusChangeListener, View.OnKeyListener, View.OnLongClickListener, View.OnTouchListener |
| Field Summary | |
|---|---|
static int |
CHILD_INDICATOR_INHERIT
Denotes when a child indicator should inherit this bound from the generic indicator bounds |
static int |
PACKED_POSITION_TYPE_CHILD
The packed position represents a child. |
static int |
PACKED_POSITION_TYPE_GROUP
The packed position represents a group. |
static int |
PACKED_POSITION_TYPE_NULL
The packed position represents a neither/null/no preference. |
static long |
PACKED_POSITION_VALUE_NULL
The value for a packed position that represents neither/null/no preference. |
| Fields inherited from class android.widget.ListView |
|---|
CHOICE_MODE_MULTIPLE, CHOICE_MODE_NONE, CHOICE_MODE_SINGLE, mDivider, mDividerHeight, NO_POSITION |
| Constructor Summary | |
|---|---|
ExpandableListView(Context context)
|
|
ExpandableListView(Context context,
AttributeSet attrs)
|
|
ExpandableListView(Context context,
AttributeSet attrs,
int defStyle)
|
|
| Method Summary | |
|---|---|
boolean |
collapseGroup(int groupPos)
Collapse a group in the grouped list view |
(package private) ContextMenu.ContextMenuInfo |
createContextMenuInfo(View view,
int flatListPosition,
long id)
Creates the ContextMenuInfo returned from AbsListView.getContextMenuInfo(). |
protected void |
dispatchDraw(Canvas canvas)
Called by draw to draw the child views. |
(package private) void |
drawDivider(Canvas canvas,
Rect bounds,
int childIndex)
Draws a divider for the given child in the given bounds. |
boolean |
expandGroup(int groupPos)
Expand a group in the grouped list view |
ListAdapter |
getAdapter()
This method should not be used, use getExpandableListAdapter(). |
ExpandableListAdapter |
getExpandableListAdapter()
Gets the adapter that provides data to this view. |
long |
getExpandableListPosition(int flatListPosition)
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). |
int |
getFlatListPosition(long packedPosition)
Converts a group and/or child position to a flat list position. |
static int |
getPackedPositionChild(long packedPosition)
Gets the child position from a packed position that is of PACKED_POSITION_TYPE_CHILD type (use getPackedPositionType(long)). |
static long |
getPackedPositionForChild(int groupPosition,
int childPosition)
Returns the packed position representation of a child's position. |
static long |
getPackedPositionForGroup(int groupPosition)
Returns the packed position representation of a group's position. |
static int |
getPackedPositionGroup(long packedPosition)
Gets the group position from a packed position. |
static int |
getPackedPositionType(long packedPosition)
Gets the type of a packed position. |
long |
getSelectedId()
Gets the ID of the currently selected group or child. |
long |
getSelectedPosition()
Gets the position of the currently selected group or child (along with its type). |
(package private) boolean |
handleItemClick(View v,
int position,
long id)
This will either expand/collapse groups (if a group was clicked) or pass on the click to the proper child (if a child was clicked) |
boolean |
isGroupExpanded(int groupPosition)
Whether the given group is currently expanded. |
void |
onRestoreInstanceState(Parcelable state)
Hook allowing a view to re-apply a representation of its internal state that had previously been generated by View.onSaveInstanceState(). |
Parcelable |
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. |
boolean |
performItemClick(View v,
int position,
long id)
Call the OnItemClickListener, if it is defined. |
void |
setAdapter(ExpandableListAdapter adapter)
Sets the adapter that provides data to this view. |
void |
setAdapter(ListAdapter adapter)
This overloaded method should not be used, instead use setAdapter(ExpandableListAdapter). |
void |
setChildDivider(Drawable childDivider)
Sets the drawable that will be drawn adjacent to every child in the list. |
void |
setChildIndicator(Drawable childIndicator)
Sets the indicator to be drawn next to a child. |
void |
setChildIndicatorBounds(int left,
int right)
Sets the drawing bounds for the child indicator. |
void |
setGroupIndicator(Drawable groupIndicator)
Sets the indicator to be drawn next to a group. |
void |
setIndicatorBounds(int left,
int right)
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). |
void |
setOnChildClickListener(ExpandableListView.OnChildClickListener onChildClickListener)
|
void |
setOnGroupClickListener(ExpandableListView.OnGroupClickListener onGroupClickListener)
|
void |
setOnGroupCollapseListener(ExpandableListView.OnGroupCollapseListener onGroupCollapseListener)
|
void |
setOnGroupExpandListener(ExpandableListView.OnGroupExpandListener onGroupExpandListener)
|
void |
setOnItemClickListener(AdapterView.OnItemClickListener l)
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. |
boolean |
setSelectedChild(int groupPosition,
int childPosition,
boolean shouldExpandGroup)
Sets the selection to the specified child. |
void |
setSelectedGroup(int groupPosition)
Sets the selection to the specified group. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface android.view.ViewParent |
|---|
createContextMenu, getParent, isLayoutRequested |
| Field Detail |
|---|
public static final int PACKED_POSITION_TYPE_GROUP
public static final int PACKED_POSITION_TYPE_CHILD
public static final int PACKED_POSITION_TYPE_NULL
public static final long PACKED_POSITION_VALUE_NULL
public static final int CHILD_INDICATOR_INHERIT
| Constructor Detail |
|---|
public ExpandableListView(Context context)
public ExpandableListView(Context context,
AttributeSet attrs)
public ExpandableListView(Context context,
AttributeSet attrs,
int defStyle)
| Method Detail |
|---|
protected void dispatchDraw(Canvas canvas)
ViewGroup
dispatchDraw in class ListViewcanvas - the canvas on which to draw the viewpublic void setChildDivider(Drawable childDivider)
ListView.setDivider(Drawable)) or
if it does not have an intrinsic height, the height set by ListView.setDividerHeight(int).
childDivider - The drawable to use.
void drawDivider(Canvas canvas,
Rect bounds,
int childIndex)
ListView
drawDivider in class ListViewcanvas - The canvas to draw to.bounds - The bounds of the divider.childIndex - The index of child (of the View) above the divider.
This will be -1 if there is no child above the divider to be
drawn.public void setAdapter(ListAdapter adapter)
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.
setAdapter in class ListViewadapter - 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.ListView.getAdapter()public ListAdapter getAdapter()
getExpandableListAdapter().
getAdapter in class ListViewListView.setAdapter(ListAdapter)public void setOnItemClickListener(AdapterView.OnItemClickListener l)
setOnGroupClickListener(android.widget.ExpandableListView.OnGroupClickListener) and/or setOnChildClickListener(android.widget.ExpandableListView.OnChildClickListener).
Register a callback to be invoked when an item in this AdapterView has
been clicked.
setOnItemClickListener in class AdapterView<ListAdapter>l - The callback that will be invoked.public void setAdapter(ExpandableListAdapter adapter)
adapter - The adapter that provides data to this view.public ExpandableListAdapter getExpandableListAdapter()
public boolean performItemClick(View v,
int position,
long id)
AdapterView
performItemClick in class ListViewv - 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.
boolean handleItemClick(View v,
int position,
long id)
position - The flat list position. This has already been factored to
remove the header/footer.id - The ListAdapter ID, not the group or child ID.public boolean expandGroup(int groupPos)
groupPos - the group to be expanded
public boolean collapseGroup(int groupPos)
groupPos - position of the group to collapse
public void setOnGroupCollapseListener(ExpandableListView.OnGroupCollapseListener onGroupCollapseListener)
public void setOnGroupExpandListener(ExpandableListView.OnGroupExpandListener onGroupExpandListener)
public void setOnGroupClickListener(ExpandableListView.OnGroupClickListener onGroupClickListener)
public void setOnChildClickListener(ExpandableListView.OnChildClickListener onChildClickListener)
public long getExpandableListPosition(int flatListPosition)
ListView's methods. Use
getPackedPositionType(long) ,
getPackedPositionChild(long),
getPackedPositionGroup(long) to unpack.
flatListPosition - The flat list position to be converted.
public int getFlatListPosition(long packedPosition)
ListView's methods.
packedPosition - The group and/or child positions to be converted in
packed position representation. Use
getPackedPositionForChild(int, int) or
getPackedPositionForGroup(int).
public long getSelectedPosition()
PACKED_POSITION_VALUE_NULL if no selection.
public long getSelectedId()
public void setSelectedGroup(int groupPosition)
groupPosition - The position of the group that should be selected.
public boolean setSelectedChild(int groupPosition,
int childPosition,
boolean shouldExpandGroup)
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.
public boolean isGroupExpanded(int groupPosition)
groupPosition - The group to check.
public static int getPackedPositionType(long packedPosition)
getPackedPositionForChild(int, int).
packedPosition - The packed position for which to return the type.
PACKED_POSITION_TYPE_CHILD, PACKED_POSITION_TYPE_GROUP, or
PACKED_POSITION_TYPE_NULL.public static int getPackedPositionGroup(long packedPosition)
getPackedPositionForChild(int, int).
packedPosition - The packed position from which the group position
will be returned.
public static int getPackedPositionChild(long packedPosition)
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.
public static long getPackedPositionForChild(int groupPosition,
int childPosition)
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.
public static long getPackedPositionForGroup(int groupPosition)
getPackedPositionForChild(int, int).
groupPosition - The child's parent group's position.
ContextMenu.ContextMenuInfo createContextMenuInfo(View view,
int flatListPosition,
long id)
AbsListViewAbsListView.getContextMenuInfo(). This
methods knows the view, position and ID of the item that received the
long press.
createContextMenuInfo in class AbsListViewview - The view that received the long press.flatListPosition - The position of the item that received the long press.id - The ID of the item that received the long press.
AbsListView.getContextMenuInfo().public void setChildIndicator(Drawable childIndicator)
childIndicator - The drawable to be used as an indicator. If the
child is the last child for a group, the state
R.attr.state_last will be set.
public void setChildIndicatorBounds(int left,
int right)
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.setIndicatorBounds(int, int)public void setGroupIndicator(Drawable groupIndicator)
groupIndicator - The drawable to be used as an indicator. If the
group is empty, the state R.attr.state_empty will be
set. If the group is expanded, the state
R.attr.state_expanded will be set.
public void setIndicatorBounds(int left,
int right)
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.setChildIndicatorBounds(int, int)public Parcelable onSaveInstanceState()
ViewSome 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.
onSaveInstanceState in class ListViewView.onRestoreInstanceState(android.os.Parcelable),
View.saveHierarchyState(android.util.SparseArray) ,
View.dispatchSaveInstanceState(android.util.SparseArray) ,
View.setSaveEnabled(boolean)public void onRestoreInstanceState(Parcelable state)
ViewView.onSaveInstanceState(). This function will never be called with a
null state.
onRestoreInstanceState in class ListViewstate - The frozen state that had previously been returned by
View.onSaveInstanceState().View.onSaveInstanceState(),
View.restoreHierarchyState(android.util.SparseArray) ,
View.dispatchRestoreInstanceState(android.util.SparseArray)
|
Build 1.0_r1(from source) | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||