Most visited

Recently visited

Added in API level 3

AlphabetIndexer

public class AlphabetIndexer
extends DataSetObserver implements SectionIndexer

java.lang.Object
   ↳ android.database.DataSetObserver
     ↳ android.widget.AlphabetIndexer


实现SectionIndexer接口的适配器的辅助类。 如果适配器中的项目通过简单的基于字母排序进行排序,则此类提供了使用二分查找快速索引大型列表的方法。 它缓存通过二进制搜索确定的索引,并且如果光标发生更改,也会使缓存无效。

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

组成索引节的字符串。

protected int mColumnIndex

此列表所在的游标列的索引。

protected Cursor mDataCursor

由列表视图的适配器使用的光标。

Public constructors

AlphabetIndexer(Cursor cursor, int sortedColumnIndex, CharSequence alphabet)

构造索引器。

Public methods

int getPositionForSection(int sectionIndex)

执行二进制搜索或高速缓存查找以查找与给定部分的首字母匹配的第一行。

int getSectionForPosition(int position)

通过查询项目并将其与节数组中的所有项目进行比较,返回列表中给定位置的节索引。

Object[] getSections()

返回从构造函数中提供的字母表构造的节数组。

void onChanged()

当整个数据集发生变化时调用此方法,很可能通过致电 requery()上的 Cursor

void onInvalidated()

当整个数据无效时调用此方法,很可能是通过调用 deactivate()close()上的 Cursor

void setCursor(Cursor cursor)

将新光标设置为数据集并重置索引缓存。

Protected methods

int compare(String word, String letter)

默认实现将单词的第一个字符与字母进行比较。

Inherited methods

From class android.database.DataSetObserver
From class java.lang.Object
From interface android.widget.SectionIndexer

Fields

mAlphabet

Added in API level 3
CharSequence mAlphabet

组成索引节的字符串。

mColumnIndex

Added in API level 3
int mColumnIndex

此列表所在的游标列的索引。

mDataCursor

Added in API level 3
Cursor mDataCursor

由列表视图的适配器使用的光标。

Public constructors

AlphabetIndexer

Added in API level 3
AlphabetIndexer (Cursor cursor, 
                int sortedColumnIndex, 
                CharSequence alphabet)

构造索引器。

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

Added in API level 3
int getPositionForSection (int sectionIndex)

执行二进制搜索或高速缓存查找以查找与给定部分的首字母匹配的第一行。

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

Added in API level 3
int getSectionForPosition (int position)

通过查询项目并将其与节数组中的所有项目进行比较,返回列表中给定位置的节索引。

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
Object[] the section array

onChanged

Added in API level 3
void onChanged ()

当整个数据集已更改时调用此方法,很可能是通过致电 requery()上的 Cursor

onInvalidated

Added in API level 3
void onInvalidated ()

当整个数据变得无效时调用此方法,很可能通过调用 deactivate()close()调用 Cursor

setCursor

Added in API level 3
void setCursor (Cursor cursor)

将新光标设置为数据集并重置索引缓存。

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

Protected methods

compare

Added in API level 3
int compare (String word, 
                String letter)

默认实现将单词的第一个字符与字母进行比较。

Parameters
word String
letter String
Returns
int

Hooray!