3

是否可以在 Android中使用 aSectionIndexer和 a ?GridView快速滚动工作正常,我正在使用扩展的自定义适配器BaseAdapter。该适配器当前正在实施SectionIndexer,并且似乎与在线和 Stack Overflow 上显示的示例相同。这让我想到是否甚至可以使用GridView自定义适配器。

4

1 回答 1

3
static class YOUR_ADAPTER extends SimpleCursorAdapter implements SectionIndexer {

private AlphabetIndexer mIndexer;

 YOUR_ADAPTER (Context context, AlbumBrowserActivity currentactivity,
            int layout, Cursor cursor, String[] from, int[] to) {
        super(context, layout, cursor, from, to);

        getColumnIndices(cursor);
    } 

    private void getColumnIndices(Cursor cursor) {
        if (cursor != null) {
            YOUR_COLUMN = cursor.getColumnIndexOrThrow(WHAT_YOU'RE_SORTING);

            if (mIndexer != null) {
                mIndexer.setCursor(cursor);
            } else {
                mIndexer = new AlphabetIndexer(cursor, YOUR_COLUMN, mResources.getString(
                        R.string.fast_scroll_alphabet));
            }
        }
    }

    @Override
    public Object[] getSections() {
        return mIndexer.getSections();
    }

    @Override   
    public int getPositionForSection(int section) {
        return mIndexer.getPositionForSection(section);
    }

    @Override
    public int getSectionForPosition(int position) {
        return 0;
    }
}

fast_scroll_alphabetString

<string name="fast_scroll_alphabet">\u0020ABCDEFGHIJKLMNOPQRSTUVWXYZ</string>

这是一个基本示例,但仅此而已。实现SectionIndexer非常简单。

于 2012-04-30T20:28:40.970 回答