Une fois que le FastScroller
(son dans AbsListView
classe qui ListView
étend à partir) obtient vos sections en appelant SectionIndexer#getSections()
, il ne les re-obtient sauf si vous activez/désactivez-le défilement rapide comme mentionné dans le lien que vous avez mentionné. Pour afficher la valeur à l'écran, FastScroller appelle la méthode toString de la section.
Une solution possible est d'avoir une coutume SectionIndexer
qui ont les caractéristiques suivantes:.
- Le tableau des sections est de longueur fixe (longueur maximale du nombre prévu de sections Par exemple, si les sections représentent anglais alphabet, il sera 26)
- avoir un objet personnalisé pour représenter les sections, plutôt que d'utiliser des chaînes
- Ecraser la méthode
toString
de votre objet section personnalisée pour afficher ce que vous voulez sur la base des « valeurs de la section » actuelles. -
par exemple. Dans votre mesure SectionIndexer
private int mLastPosition;
public int getPositionForSection(int sectionIndex) {
if (sectionIndex < 0) sectionIndex = 0;
// myCurrentSectionLength is the number of sections you want to have after
// re-indexing the items in your ListView
// NOTE: myCurrentSectionLength must be less than getSections().length
if (sectionIndex >= myCurrentSectionLength) sectionIndex = myCurrentSectionLength - 1;
int position = 0;
// --- your logic to find the position goes in here
// --- e.g. see the AlphabeticIndexer source in Android repo for an example
mLastPosition = position;
return mLastPosition;
}
public Object[] getSections() {
// Assume you only have at most 3 section for this example
return new MySection[]{new MySection(), new MySection(), new MySection()};
}
// inner class within your CustomSectionIndexer
public class MySection {
MySection() {}
public String toString() {
// Get the value to displayed based on mLastPosition and the list item within that position
return "some value";
}
}
que je fais quelque chose de similaire ICI http://stackoverflow.com/questions/10224233/alphabetindexer-with-custom-adapter-managed-by-loadermanager – toobsco42