Skip to content

Most visited

Recently visited

navigation
added in API level 3

SectionIndexer

public interface SectionIndexer

android.widget.SectionIndexer
Known Indirect Subclasses


Interface that may implemented on Adapters 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.

ExpandableListAdapters that consider groups and sections as synonymous should account for collapsed groups and return an appropriate section/position.

See also:

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

added in API level 3
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

added in API level 3
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

added in API level 3
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

This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields

Hooray!

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a short survey?
Help us improve the Android developer experience.
(Sep 2017 survey)