我的listfragment有一个实现CursorAdapter
的自定义SectionIndexer
。我使用AlphabetIndexer
助手类以简单的标准方式实现SectionIndexer
。但由于某些原因,在滚动时,滚动中的字符从K变为R,跳过其间的所有字母。因此,即使有数十个条目以L,M,N,O,P,Q开头,它们都在K部分下面。如果我从AlphabetIndexer的alphabet参数中删除K,则相同的行为仍然存在于L知道为什么会这样吗?
private class ContactsAdapter extends CursorAdapter implements SectionIndexer {
private AlphabetIndexer mAlphabetIndexer; // Stores the AlphabetIndexer instance
...
public ContactsAdapter(Context context) {
...
final String alphabet = context.getString(R.string.alphabet); // alphabet=" ABCDEFGHIJKLMNOPQRSTUVWXYZ"
mAlphabetIndexer = new AlphabetIndexer(null, ContactsQuery.SORT_KEY, alphabet);
/**
* An override of getCount that simplifies accessing the Cursor. If the Cursor is null,
* getCount returns zero. As a result, no test for Cursor == null is needed.
*/
@Override
public int getCount() {
if (getCursor() == null) {
return 0;
}
return super.getCount();
}
@Override
public Cursor swapCursor(Cursor newCursor) {
// Update the AlphabetIndexer with new cursor as well
mAlphabetIndexer.setCursor(newCursor);
return super.swapCursor(newCursor);
}
@Override
public Object[] getSections() {
return mAlphabetIndexer.getSections();
}
/**
* Defines the SectionIndexer.getPositionForSection() interface.
*/
@Override
public int getPositionForSection(int i) {
if (getCursor() == null) {
return 0;
}
return mAlphabetIndexer.getPositionForSection(i);
}
/**
* Defines the SectionIndexer.getSectionForPosition() interface.
*/
@Override
public int getSectionForPosition(int i) {
if (getCursor() == null) {
return 0;
}
return mAlphabetIndexer.getSectionForPosition(i);
}
}
}