Stay organized with collections
Save and categorize content based on your preferences.
SectionIndexer
public
interface
SectionIndexer
android.widget.SectionIndexer
|
Known indirect subclasses
AlphabetIndexer |
A helper class for adapters that implement the SectionIndexer interface.
|
|
Interface that may implemented on Adapter
s to enable fast scrolling
between sections of an AbsListView
.
A section is a group of list items that have something in common. For
example, they may begin with the same letter or they may be songs from the
same artist.
ExpandableListAdapter
s that consider groups and sections as
synonymous should account for collapsed groups and return an appropriate
section/position.
Summary
Public methods |
abstract
int
|
getPositionForSection(int sectionIndex)
Given the index of a section within the array of section objects, returns
the starting position of that section within the adapter.
|
abstract
int
|
getSectionForPosition(int position)
Given a position within the adapter, returns the index of the
corresponding section within the array of section objects.
|
abstract
Object[]
|
getSections()
Returns an array of objects representing sections of the list.
|
Public methods
getPositionForSection
public abstract int getPositionForSection (int sectionIndex)
Given the index of a section within the array of section objects, returns
the starting position of that section within the adapter.
If the section's starting position is outside of the adapter bounds, the
position must be clipped to fall within the size of the adapter.
Parameters |
sectionIndex |
int : the index of the section within the array of section
objects |
Returns |
int |
the starting position of that section within the adapter,
constrained to fall within the adapter bounds |
getSectionForPosition
public abstract int getSectionForPosition (int position)
Given a position within the adapter, returns the index of the
corresponding section within the array of section objects.
If the section index is outside of the section array bounds, the index
must be clipped to fall within the size of the section array.
For example, consider an indexer where the section at array index 0
starts at adapter position 100. Calling this method with position 10,
which is before the first section, must return index 0.
Parameters |
position |
int : the position within the adapter for which to return the
corresponding section index |
Returns |
int |
the index of the corresponding section within the array of
section objects, constrained to fall within the array bounds |
getSections
public abstract Object[] getSections ()
Returns an array of objects representing sections of the list. The
returned array and its contents should be non-null.
The list view will call toString() on the objects to get the preview text
to display while scrolling. For example, an adapter may return an array
of Strings representing letters of the alphabet. Or, it may return an
array of objects whose toString() methods return their section titles.
Returns |
Object[] |
the array of section objects |
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-02-10 UTC."],[],[],null,["# SectionIndexer\n\nAdded in [API level 3](/guide/topics/manifest/uses-sdk-element#ApiLevels) \nSummary: [Methods](#pubmethods) \n\nSectionIndexer\n==============\n\n*** ** * ** ***\n\n[Kotlin](/reference/kotlin/android/widget/SectionIndexer \"View this page in Kotlin\") \\|Java\n\n\n`\npublic\n\n\ninterface\nSectionIndexer\n`\n\n\n`\n\n\n`\n\n|-------------------------------|\n| android.widget.SectionIndexer |\n\n|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| Known indirect subclasses [AlphabetIndexer](/reference/android/widget/AlphabetIndexer) |--------------------------------------------------------------|--------------------------------------------------------------------------| | [AlphabetIndexer](/reference/android/widget/AlphabetIndexer) | A helper class for adapters that implement the SectionIndexer interface. | |\n\n\u003cbr /\u003e\n\n*** ** * ** ***\n\nInterface that may implemented on [Adapter](/reference/android/widget/Adapter)s to enable fast scrolling\nbetween sections of an [AbsListView](/reference/android/widget/AbsListView).\n\n\nA section is a group of list items that have something in common. For\nexample, they may begin with the same letter or they may be songs from the\nsame artist.\n\n\n[ExpandableListAdapter](/reference/android/widget/ExpandableListAdapter)s that consider groups and sections as\nsynonymous should account for collapsed groups and return an appropriate\nsection/position. \n**See also:**\n\n- [AbsListView.setFastScrollEnabled(boolean)](/reference/android/widget/AbsListView#setFastScrollEnabled(boolean))\n\nSummary\n-------\n\n| ### Public methods ||\n|-----------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| ` abstract int` | ` `[getPositionForSection](/reference/android/widget/SectionIndexer#getPositionForSection(int))`(int sectionIndex) ` Given the index of a section within the array of section objects, returns the starting position of that section within the adapter. |\n| ` abstract int` | ` `[getSectionForPosition](/reference/android/widget/SectionIndexer#getSectionForPosition(int))`(int position) ` Given a position within the adapter, returns the index of the corresponding section within the array of section objects. |\n| ` abstract `[Object[]](/reference/java/lang/Object) | ` `[getSections](/reference/android/widget/SectionIndexer#getSections())`() ` Returns an array of objects representing sections of the list. |\n\nPublic methods\n--------------\n\n### getPositionForSection\n\nAdded in [API level 3](/guide/topics/manifest/uses-sdk-element#ApiLevels) \n\n```\npublic abstract int getPositionForSection (int sectionIndex)\n```\n\nGiven the index of a section within the array of section objects, returns\nthe starting position of that section within the adapter.\n\n\nIf the section's starting position is outside of the adapter bounds, the\nposition must be clipped to fall within the size of the adapter.\n\n\u003cbr /\u003e\n\n| Parameters ||\n|----------------|----------------------------------------------------------------------------|\n| `sectionIndex` | `int`: the index of the section within the array of section objects \u003cbr /\u003e |\n\n| Returns ||\n|-------|----------------------------------------------------------------------------------------------------------------|\n| `int` | the starting position of that section within the adapter, constrained to fall within the adapter bounds \u003cbr /\u003e |\n\n### getSectionForPosition\n\nAdded in [API level 3](/guide/topics/manifest/uses-sdk-element#ApiLevels) \n\n```\npublic abstract int getSectionForPosition (int position)\n```\n\nGiven a position within the adapter, returns the index of the\ncorresponding section within the array of section objects.\n\n\nIf the section index is outside of the section array bounds, the index\nmust be clipped to fall within the size of the section array.\n\n\nFor example, consider an indexer where the section at array index 0\nstarts at adapter position 100. Calling this method with position 10,\nwhich is before the first section, must return index 0.\n\n\u003cbr /\u003e\n\n| Parameters ||\n|------------|---------------------------------------------------------------------------------------------------|\n| `position` | `int`: the position within the adapter for which to return the corresponding section index \u003cbr /\u003e |\n\n| Returns ||\n|-------|--------------------------------------------------------------------------------------------------------------------------------|\n| `int` | the index of the corresponding section within the array of section objects, constrained to fall within the array bounds \u003cbr /\u003e |\n\n### getSections\n\nAdded in [API level 3](/guide/topics/manifest/uses-sdk-element#ApiLevels) \n\n```\npublic abstract Object[] getSections ()\n```\n\nReturns an array of objects representing sections of the list. The\nreturned array and its contents should be non-null.\n\n\nThe list view will call toString() on the objects to get the preview text\nto display while scrolling. For example, an adapter may return an array\nof Strings representing letters of the alphabet. Or, it may return an\narray of objects whose toString() methods return their section titles.\n\n\u003cbr /\u003e\n\n| Returns ||\n|-----------------------------------------|-------------------------------------|\n| [Object[]](/reference/java/lang/Object) | the array of section objects \u003cbr /\u003e |"]]