thought I'd post here in the hopes that it's not too late.
Note: This is not using an AlphabetIndexer, and I don't think using three collections to manage a list is a good idea, though it is simple, and explains the concept.
Below is a basic example of how to use the callbacks:
public LinkedHashMap<Integer,String> sectionList = new LinkedHashMap<Integer,String>();
public HashMap<Integer,Integer> sectionPositions = new HashMap<Integer, Integer>();
public HashMap<Integer,Integer> positionsForSection = new HashMap<Integer, Integer>();
When you have your "locations" array (pre-ordered), this will create three hashmaps to track things, really simple implementation, really easy to read :
if( locations != null && locations.size() > 0 ) {
//Iterate through the contacts, take the first letter, uppercase it, and use that as a key to reference the alphabetised list constructed above.
for( int i = 0; i < locations.size(); i++ ) {
String startchar =locations.get(i).getStartCharacterForAlphabet();
if( startchar != null ) {
if( sectionList.containsValue(startchar) == false ) {
sectionList.put(Integer.valueOf(i),startchar);
positionsForSection.put(Integer.valueOf(sectionList.size() - 1), Integer.valueOf(i));
}
}
sectionPositions.put(Integer.valueOf(i), sectionList.size() - 1);
}
}
And here are the three callbacks:
@Override
public int getPositionForSection(int section) {
return positionsForSection.get(Integer.valueOf(section)).intValue();
}
@Override
public MyLocation getItem(int position) {
if( locations.size() > position ) {
return locations.get(position);
}
return null;
}
@Override
public int getSectionForPosition(int position) {
return sectionPositions.get(Integer.valueOf(position)).intValue();
}
Hope it helps!