public abstract class ExpandableListFragment extends Fragment
A fragment that displays an expandable list of items by binding to a data source provided through the use of adapters, and exposes event handlers when the user selects an item.
ExpandableListFragment hosts a ExpandableListView
object that can be bound to different data sources.
Binding to Data
You bind the ExpandableListFragment's ExpandableListView object to data using a class that
implements the ExpandableListAdapter interface.
You must use ExpandableListFragment.setListAdapter() to
associate the list with an adapter. Do not directly call ExpandableListView.setAdapter() or else important initialization will be skipped.
setListAdapter(android.widget.ExpandableListAdapter),
ExpandableListViewFragment.InstantiationException, Fragment.SavedState| Modifier and Type | Field and Description |
|---|---|
protected static String |
STATE_EXPANDED_GROUPS |
| Constructor and Description |
|---|
ExpandableListFragment() |
| Modifier and Type | Method and Description |
|---|---|
void |
expandGroups()
Expand the groups that have been set to be expanded, in case it could not be done automatically
during setting the expanded groups.
|
int[] |
getExpandedGroups()
Returns the positions of the currently expanded groups.
|
ExpandableListAdapter |
getListAdapter()
Get the ListAdapter associated with this activity's ListView.
|
ExpandableListView |
getListView()
Get the activity's list view widget.
|
long |
getSelectedItemId()
Get the cursor row ID of the currently selected list item.
|
int |
getSelectedItemPosition()
Get the position of the currently selected list item.
|
View |
onCreateView(LayoutInflater inflater,
ViewGroup container,
Bundle savedInstanceState) |
void |
onDestroyView() |
protected abstract boolean |
onListChildClick(ExpandableListView parent,
View view,
int groupPosition,
int childPosition,
long id)
This method will be called when a child item in the list is selected.
|
void |
onResume() |
void |
onSaveInstanceState(Bundle outState) |
void |
onViewCreated(View view,
Bundle savedInstanceState) |
void |
onViewStateRestored(Bundle savedInstanceState) |
void |
setEmptyText(CharSequence text)
The default content for an ExpandableListFragment has a TextView that can
be shown when the list is empty.
|
void |
setExpandedGroups(int[] groupPositions)
Sets the expanded groups.
|
void |
setListAdapter(ExpandableListAdapter adapter)
Provide the data binding for the list view.
|
void |
setListShown(boolean shown)
Control whether the list is being displayed.
|
void |
setListShownNoAnimation(boolean shown)
Like
setListShown(boolean), but no animation is used when
transitioning from the previous state. |
void |
setSelection(int position)
Set the currently selected list item to the specified
position with the adapter's data
|
dump, equals, getActivity, getAllowEnterTransitionOverlap, getAllowReturnTransitionOverlap, getArguments, getChildFragmentManager, getEnterTransition, getExitTransition, getFragmentManager, getId, getLayoutInflater, getLoaderManager, getParentFragment, getReenterTransition, getResources, getRetainInstance, getReturnTransition, getSharedElementEnterTransition, getSharedElementReturnTransition, getString, getString, getTag, getTargetFragment, getTargetRequestCode, getText, getUserVisibleHint, getView, hashCode, hasOptionsMenu, instantiate, instantiate, isAdded, isDetached, isHidden, isInLayout, isMenuVisible, isRemoving, isResumed, isVisible, onActivityCreated, onActivityResult, onAttach, onConfigurationChanged, onContextItemSelected, onCreate, onCreateAnimation, onCreateContextMenu, onCreateOptionsMenu, onDestroy, onDestroyOptionsMenu, onDetach, onHiddenChanged, onInflate, onLowMemory, onOptionsItemSelected, onOptionsMenuClosed, onPause, onPrepareOptionsMenu, onStart, onStop, registerForContextMenu, setAllowEnterTransitionOverlap, setAllowReturnTransitionOverlap, setArguments, setEnterSharedElementCallback, setEnterTransition, setExitSharedElementCallback, setExitTransition, setHasOptionsMenu, setInitialSavedState, setMenuVisibility, setReenterTransition, setRetainInstance, setReturnTransition, setSharedElementEnterTransition, setSharedElementReturnTransition, setTargetFragment, setUserVisibleHint, startActivity, startActivityForResult, toString, unregisterForContextMenuprotected static final String STATE_EXPANDED_GROUPS
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
onCreateView in class Fragmentpublic void onViewCreated(View view, Bundle savedInstanceState)
onViewCreated in class Fragmentpublic void onViewStateRestored(Bundle savedInstanceState)
onViewStateRestored in class Fragmentpublic void onSaveInstanceState(Bundle outState)
onSaveInstanceState in class Fragmentpublic void onDestroyView()
onDestroyView in class Fragmentprotected abstract boolean onListChildClick(ExpandableListView parent, View view, int groupPosition, int childPosition, long id)
parent - The ExpandableListView that is hosting the child.view - The View that represents the child in the list view.groupPosition - the index of the groupchildPosition - the index of the childid - the ID of the child as returned by the adapter.true if even was handled, false if not.public void setListAdapter(ExpandableListAdapter adapter)
adapter - the ExpandableListAdapter binding the data to the view.public void setSelection(int position)
position - the index of the item to select.public int getSelectedItemPosition()
public long getSelectedItemId()
public ExpandableListView getListView()
ExpandableListView of this fragment.public void setEmptyText(CharSequence text)
text - The text to be shown when the list is empty.public void setListShown(boolean shown)
Applications do not normally need to use this themselves. The default
behavior of ListFragment is to start with the list not being shown, only
showing it once an adapter is given with setListAdapter(ExpandableListAdapter).
If the list at that point had not been shown, when it does get shown
it will be do without the user ever seeing the hidden state.
shown - If true, the list view is shown; if false, the progress indicator. The initial value is true.public void setListShownNoAnimation(boolean shown)
setListShown(boolean), but no animation is used when
transitioning from the previous state.public ExpandableListAdapter getListAdapter()
public int[] getExpandedGroups()
Returns the positions of the currently expanded groups.
"Positions" means the index of the group within the used ExpandableListAdapter's
underlying data structure.
public void setExpandedGroups(int[] groupPositions)
Sets the expanded groups. All group positions in the provided array will be expanded.
"Positions" means the index of the group within the used ExpandableListAdapter's
underlying data structure.
groupPositions - Group positions to expand.public void expandGroups()
Expand the groups that have been set to be expanded, in case it could not be done automatically during setting the expanded groups.
In case the groups are already expanded, the method will simply return without doing anything.