Indexer section with gridview in Android

Can i use SectionIndexerwith GridViewin android? Fast scrolling works fine, and I use a custom adapter that extends BaseAdapter. The adapter currently implements SectionIndexerand appears to be identical to the examples shown online and overflow the stack. This made me wonder if this could be done with a GridViewcustom adapter either.

+3
source share
1 answer
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_alphabet String

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

This is a basic example, but there is not much more than that. The implementation is SectionIndexerpretty simple.

+3
source

All Articles