# Print output for @column tags ?>
Developers

- Design
- Develop
- Distribute

Developer Console

## Most visited

## Recently visited

## Results for

Summary: Fields | Ctors | Methods | Protected Methods | Inherited Methods

# AlphabetIndexer

`public class AlphabetIndexer`
`` `extends DataSetObserver` `implements SectionIndexer`

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 calling `setCursor(Cursor)` if the cursor changes. `getPositionForSection(int)` method does the binary search for the starting index of a given section (alphabet).

## Summary

### Fields
`protected CharSequence` | `mAlphabet` The string of characters that make up the indexing sections.
`protected int` | `mColumnIndex` The index of the cursor column that this list is sorted on.
`protected Cursor` | `mDataCursor` Cursor that is used by the adapter of the list view.

### Public constructors
`AlphabetIndexer(Cursor cursor, int sortedColumnIndex, CharSequence alphabet)` Constructs the indexer.

### Public methods
`int` | `getPositionForSection(int sectionIndex)` Performs a binary search or cache lookup to find the first row that matches a given section's starting letter.
`int` | `getSectionForPosition(int position)` 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.
`Object[]` | `getSections()` Returns the section array constructed from the alphabet provided in the constructor.
`void` | `onChanged()` This method is called when the entire data set has changed, most likely through a call to `Cursor#requery()` on a `Cursor`.
`void` | `onInvalidated()` This method is called when the entire data becomes invalid, most likely through a call to `Cursor#deactivate()` or `Cursor#close()` on a `Cursor`.
`void` | `setCursor(Cursor cursor)` Sets a new cursor as the data set and resets the cache of indices.

### Protected methods
`int` | `compare(String word, String letter)` Default implementation compares the first character of word with letter.

### Inherited methods
From class `android.database.DataSetObserver`
`void` | `onChanged()` This method is called when the entire data set has changed, most likely through a call to `Cursor#requery()` on a `Cursor`.
`void` | `onInvalidated()` This method is called when the entire data becomes invalid, most likely through a call to `Cursor#deactivate()` or `Cursor#close()` on a `Cursor`.
From class `java.lang.Object`
`Object` | `clone()` Creates and returns a copy of this object.
`boolean` | `equals(Object obj)` Indicates whether some other object is "equal to" this one.
`void` | `finalize()` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
`final Class<?>` | `getClass()` Returns the runtime class of this `Object`.
`int` | `hashCode()` Returns a hash code value for the object.
`final void` | `notify()` Wakes up a single thread that is waiting on this object's monitor.
`final void` | `notifyAll()` Wakes up all threads that are waiting on this object's monitor.
`String` | `toString()` Returns a string representation of the object.
`final void` | `wait(long timeout, int nanos)` Causes the current thread to wait until another thread invokes the `notify()` method or the `notifyAll()` method for this object, or some other thread interrupts the current thread, or a certain amount of real time has elapsed.
`final void` | `wait(long timeout)` Causes the current thread to wait until either another thread invokes the `notify()` method or the `notifyAll()` method for this object, or a specified amount of time has elapsed.
`final void` | `wait()` Causes the current thread to wait until another thread invokes the `notify()` method or the `notifyAll()` method for this object.
From interface `android.widget.SectionIndexer`
`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.

## Fields

### mAlphabet

    protected CharSequence mAlphabet

The string of characters that make up the indexing sections.

### mColumnIndex

    protected int mColumnIndex

The index of the cursor column that this list is sorted on.

### mDataCursor

    protected Cursor mDataCursor

Cursor that is used by the adapter of the list view.

## Public constructors

### AlphabetIndexer

    public AlphabetIndexer (Cursor cursor,
                    int sortedColumnIndex,
                    CharSequence alphabet)

Constructs the indexer.

Parameters
`cursor` | `Cursor`: the cursor containing the data set
`sortedColumnIndex` | `int`: the column number in the cursor that is sorted alphabetically
`alphabet` | `CharSequence`: 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.

## Public methods

### getPositionForSection

    public int getPositionForSection (int sectionIndex)

Performs a binary search or cache lookup to find the first row that matches a given section's starting letter.

Parameters
`sectionIndex` | `int`: the section to search for

Returns
`int` | the row index of the first occurrence, or the nearest next letter. For instance, if searching for "T" and no "T" is found, then the first row starting with "U" or any higher letter is returned. If there is no data following "T" at all, then the list size is returned.

### getSectionForPosition

    public int getSectionForPosition (int position)

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.

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 Object[] getSections ()

Returns the section array constructed from the alphabet provided in the constructor.

Returns
`Object[]` | the section array

### onChanged

    public void onChanged ()

This method is called when the entire data set has changed, most likely through a call to `Cursor#requery()` on a `Cursor`.

### onInvalidated

    public void onInvalidated ()

This method is called when the entire data becomes invalid, most likely through a call to `Cursor#deactivate()` or `Cursor#close()` on a `Cursor`.

### setCursor

    public void setCursor (Cursor cursor)

Sets a new cursor as the data set and resets the cache of indices.

Parameters
`cursor` | `Cursor`: the new cursor to use as the data set

## Protected methods

### compare

    protected int compare (String word,
                    String letter)

Default implementation compares the first character of word with letter.

Parameters
`word` | `String`
`letter` | `String`

Returns
`int` |

Full name *
Email address *
Company / developer name
One of your Play Store app URLs *
Which best describes your business:*
Apps
Games
Apps & Games
*
*