AlphabetIndexer with Custom Adapter

前端 未结 2 457
谎友^
谎友^ 2020-12-08 23:41

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,

2条回答
  •  长情又很酷
    2020-12-09 00:13

    Hi this is how I use 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();
        }
    }
    

    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.

提交回复
热议问题