java.lang.Object | ||
↳ | android.database.DataSetObserver | |
↳ | android.widget.AlphabetIndexer |
A helper class for adapters that implement the SectionIndexer interface. If the items in the adapter are sorted by simple alphabet-based sorting, then this class provides a way to do fast indexing of large lists using binary search. It caches the indices that have been determined through the binary search and also invalidates the cache if changes occur in the cursor.
Your adapter is responsible for updating the cursor by callingsetCursor(Cursor)
if the
cursor changes. getPositionForSection(int)
method does the binary search for the starting
index of a given section (alphabet).
Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
mAlphabet | The string of characters that make up the indexing sections. | ||||||||||
mColumnIndex | The index of the cursor column that this list is sorted on. | ||||||||||
mDataCursor | Cursor that is used by the adapter of the list view. |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Constructs the indexer.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Performs a binary search or cache lookup to find the first row that
matches a given section's starting letter.
| |||||||||||
Returns the section index for a given position in the list by querying the item
and comparing it with all items in the section array.
| |||||||||||
Returns the section array constructed from the alphabet provided in the constructor.
| |||||||||||
This method is called when the entire data becomes invalid,
most likely through a call to
deactivate() or close() on a
Cursor . | |||||||||||
Sets a new cursor as the data set and resets the cache of indices.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Default implementation compares the first character of word with letter.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class android.database.DataSetObserver
| |||||||||||
From class java.lang.Object
| |||||||||||
From interface android.widget.SectionIndexer
|
The string of characters that make up the indexing sections.
The index of the cursor column that this list is sorted on.
Cursor that is used by the adapter of the list view.
Constructs the indexer.
cursor | the cursor containing the data set |
---|---|
sortedColumnIndex | the column number in the cursor that is sorted alphabetically |
alphabet | string containing the alphabet, with space as the first character. For example, use the string " ABCDEFGHIJKLMNOPQRSTUVWXYZ" for English indexing. The characters must be uppercase and be sorted in ascii/unicode order. Basically characters in the alphabet will show up as preview letters. |
Performs a binary search or cache lookup to find the first row that matches a given section's starting letter.
sectionIndex | the section to search for |
---|
Returns the section index for a given position in the list by querying the item and comparing it with all items in the section array.
position | the position for which to return the section |
---|
Returns the section array constructed from the alphabet provided in the constructor.
This method is called when the entire data becomes invalid,
most likely through a call to deactivate()
or close()
on a
Cursor
.
Sets a new cursor as the data set and resets the cache of indices.
cursor | the new cursor to use as the data set |
---|
Default implementation compares the first character of word with letter.