An ExpandableListView is a view that shows items in a vertically scrolling two-level list. You can imagine it's a form of a ListView given the name or the fact that it derives from it, however
ExpandableListView is obviously more complex in that it's view items can be expanded and collapsed.
It allows two levels:
ExpandableListView is the
ExpandableListAdapter. It is this adapter that supplies items to populate our
ExpandableListView isn't young, even if alot of developers haven't used it yet. It has existed since the beginning of android, API level 1.
As a class it derives from [ListView](/android/listview:
public class ExpandableListView extends ListView
Both reside in the
ExpandableListView's inheritance hierarchy:
java.lang.Object ↳ android.view.View ↳ android.view.ViewGroup ↳ android.widget.AdapterView<android.widget.ListAdapter> ↳ android.widget.AbsListView ↳ android.widget.ListView ↳ android.widget.ExpandableListView
Beside the item views in your ExpandableListView normally you see an indicator. This visually notifies you that you need to either expand to see more content or close the child. They tell you the current state of the expandable listview.
These states can be:
These indicators can be set using the
setGroupIndicator(Drawable) (or the corresponding XML attributes).
The default style for an
ExpandableListView provides indicators which will be shown next to Views given to the ExpandableListView.
android.R.layout.simple_expandable_list_item_2 (which should be used with
SimpleCursorTreeAdapter) contain the preferred position information for indicators.
You can find more documentation about ExpandableListView here.
Let's look at some examples.
Everyone knows and loves android listviews.However, listviews have a more powerful sister known as
ExpandableListeView. These are views that show items in a vertically scrolling two-level list.
This is powerful when you want to group items in a list. The items groups can be expanded to show their children, which are also lists themselves. ExpandableListViews should not be confused with accordions.
They are lists inside list items. ExpandableListView items come from ExpandableListAdapter. ExpandableListViews do derive from ListViews, hence having the flexibility and capability of Listviews themselves.
They are simply ListViews nested inside ListView Items. They were added to android in API Level 1, so have actually been around for along time even though most people are obsessed with ListViews and RecyclerViews.