In my project I have class that extends ArrayAdapter
and implements SectionIndexer
. When implementing methods getPositionForSec
Your callback method getPositionForSection(int section) needs to be implemented to give the right position which is used by setSelection to return the right position where you want to scroll on touch of SectionIndexer on rightside.
Make sure you are doing this
this.setSelection(((SectionIndexer) getAdapter()) .getPositionForSection(currentPosition));
You need to implement two callback methods
@Override
public Object[] getSections() {
Log.d("ListView", "Get sections");
String[] sectionsArr = new String[sections.length()];
for (int i=0; i < sections.length(); i++)
sectionsArr[i] = "" + sections.charAt(i);
return sectionsArr;
}
This final callback and you are done here
@Override
public int getPositionForSection(int section){
Log.d("ListView", "Get position for section");
for (int i=0; i < this.getCount(); i++) {
String item = this.getItem(i).toLowerCase();
if (item.charAt(0) == sections.charAt(section))
return i;
}
return 0;
}