Skip to content Skip to sidebar Skip to footer

Alphabetindexer With Custom Adapter

Can someone show me an example of how to use AlphabetIndexer with a Custom Adapter that uses a getView? I have it working with a standard adapter, but have no clue how to implemen

Solution 1:

If you're using a LoaderManager to manage your adapter's cursor, you'll want to make a small adjustment and override your adapters swapCursor method:

publicCursorswapCursor(Cursor c) {
    // Create our indexerif (c != null) {
        mIndexer = newAlphabetIndexer(c, c.getColumnIndex(Books.TITLE),
                " ABCDEFGHIJKLMNOPQRSTUVWXYZ");
     }
     returnsuper.swapCursor(c);
 }

Everything else remains just as @vsm describes.

Solution 2:

Hi this is how I use AlphaIndexer

privatefinalclassContactListItemAdapterextendsResourceCursorAdapterimplementsSectionIndexer {
    AlphabetIndexer alphaIndexer;

    publicContactListItemAdapter(Context context, int layout, Cursor c) {
        super(context, layout, c);
        alphaIndexer = newAlphabetIndexer(c, NAME_COLUMN_INDEX,
                " ABCDEFGHIJKLMNOPQRSTUVWXYZ");
    }   

    @Overridepublic View getView(int position, View convertView, ViewGroup parent) {
            .... 
            a normal getView
            ....
    }  

    publicintgetPositionForSection(int section) {
        return alphaIndexer.getPositionForSection(section);
    }

    publicintgetSectionForPosition(int position) {
        return alphaIndexer.getSectionForPosition(position);
    }

    public Object[] getSections() {
        return alphaIndexer.getSections();
    }
}

NAME_COLUMN_INDEX is the index of the column in database schema.

...

If this is not what you need, please add some code about which should be the class to extend and so on.

Anyway I hope this helps.

Post a Comment for "Alphabetindexer With Custom Adapter"