如果您使用LoaderManager来管理适配器的光标,则需要进行小的调整并覆盖适配器的swapCursor方法:
public Cursor swapCursor(Cursor c) {
// Create our indexer
if (c != null) {
mIndexer = new AlphabetIndexer(c, c.getColumnIndex(Books.TITLE),
" ABCDEFGHIJKLMNOPQRSTUVWXYZ");
}
return super.swapCursor(c);
}
Run Code Online (Sandbox Code Playgroud)
其他所有内容都像@vsm描述的那样.
嗨这就是我使用AlphaIndexer的方式
private final class ContactListItemAdapter extends ResourceCursorAdapter
implements SectionIndexer {
AlphabetIndexer alphaIndexer;
public ContactListItemAdapter(Context context, int layout, Cursor c) {
super(context, layout, c);
alphaIndexer = new AlphabetIndexer(c, NAME_COLUMN_INDEX,
" ABCDEFGHIJKLMNOPQRSTUVWXYZ");
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
....
a normal getView
....
}
public int getPositionForSection(int section) {
return alphaIndexer.getPositionForSection(section);
}
public int getSectionForPosition(int position) {
return alphaIndexer.getSectionForPosition(position);
}
public Object[] getSections() {
return alphaIndexer.getSections();
}
}
Run Code Online (Sandbox Code Playgroud)
NAME_COLUMN_INDEX是数据库模式中列的索引.
...
如果这不是您所需要的,请添加一些代码,这些代码应该是要扩展的类等等.
无论如何,我希望这有帮助.
| 归档时间: |
|
| 查看次数: |
9436 次 |
| 最近记录: |