我试图AlphabetIndexer用这样的自定义适配器实现
我的类ContactsCursorAdapter扩展SimpleCursorAdapter和实现SectionIndexer
,我使用a LoaderManager来管理我的适配器的光标,所以我已经覆盖了swapCursor()方法,就像上面示例的第二个答案所示.
public class ContactsCursorAdapter extends SimpleCursorAdapter
implements SectionIndexer{
private LayoutInflater mInflater;
private Context mContext;
private AlphabetIndexer mAlphaIndexer;
public ContactsCursorAdapter(Context context, int layout, Cursor c,
String[] from, int[] to) {
super(context, layout, c, from, to);
mInflater = LayoutInflater.from(context);
mContext = context;
}
public View getView(final int position, View convertView, ViewGroup parent) {
...
}
@Override
public int getPositionForSection(int section) {
return mAlphaIndexer.getPositionForSection(section);
}
@Override
public int getSectionForPosition(int position) { …Run Code Online (Sandbox Code Playgroud) android adapter simplecursoradapter android-loadermanager android-cursorloader