Comment créer un indexeur de section catégorique pour un listview avec un tableau de chaînes? J'ai vu des exemples d'indexeur d'alphabet, mais comment est-il mis en œuvre pour les catégories, par ex. Section 1, Section 2, Section 3 ...?tutoriel android sectionindexer?
2
A
Répondre
3
Beaucoup de réponses ici:
- Creating categories in a ListView?
- AlphabetIndexer with Custom Adapter managed by LoaderManager
- http://tribulant.com/forums/topic/how-do-i-get-a-list-view-of-categories-with-image-thumbnail-and-description
Merci à tous pour les références
4
Personnaliser ce que l'adaptateur que pour vos besoins et ensemble à votre liste voir c'est tout, pris de m here
public class ContactsAdapter extends BaseAdapter implements SectionIndexer {
Context context;
String[] strings;
String[] sections ;
HashMap<String, Integer> alphaIndexer;
public ContactsAdapter(Context context, String[] strings) {
this.context = context;
this.strings = strings;
alphaIndexer = new HashMap<String, Integer>();
int size = strings.length;
for (int x = 0; x < size; x++) {
String s = strings[x];
String ch = s.substring(0, 1);
ch = ch.toUpperCase();
if (!alphaIndexer.containsKey(ch))
alphaIndexer.put(ch, x);
}
Set<String> sectionLetters = alphaIndexer.keySet();
ArrayList<String> sectionList = new ArrayList<>(sectionLetters);
Collections.sort(sectionList);
sections = new String[sectionList.size()];
sectionList.toArray(sections);
}
@Override
public int getCount() {
return strings.length;
}
@Override
public Object getItem(int position) {
return strings[position];
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = LayoutInflater.from(context).inflate(R.layout.main, parent, false);
holder = new ViewHolder();
holder.text = (TextView) convertView.findViewById(R.id.tv_contact);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.text.setText(strings[position]);
return convertView;
}
@Override
public Object[] getSections() {
return sections;
}
@Override
public int getPositionForSection(int sectionIndex) {
return alphaIndexer.get(sections[sectionIndex]);
}
@Override
public int getSectionForPosition(int position) {
return 0;
}
static class ViewHolder {
TextView text;
}
}
Sur votre vue liste
ContactsAdapter contactsAdapter = new ContactsAdapter(Registration.this, YOUR_Array;
listview.setAdapter(contactsAdapter);
listview.setFastScrollEnabled(true);
Questions connexes
- 1. Android: comment utiliser SectionIndexer
- 2. android - SimpleAdapter + SectionIndexer
- 3. SectionIndexer avec GridView dans Android
- 4. Android: présentation de vue personnalisée pour SectionIndexer et désactivation de SectionIndexer à la volée
- 5. Styling the sectionIndexer
- 6. ListAdapter avec implémenté SectionIndexer throws ClassCastException
- 7. Android SectionIndexer n'affiche pas l'aperçu alphabétique au-delà de "A"
- 8. BaseAdapter et SectionIndexer sur ListView
- 9. Ré-indexer/Actualiser un sectionIndexer
- 10. Tutoriel Android 'HelloTabWidget'
- 11. tutoriel sur Android Bluetooth
- 12. Tutoriel Jni pour android
- 13. Tutoriel Android SQLite 3
- 14. tutoriel Android hellospinner
- 15. Android Tutoriel HelloGallery Problème
- 16. erreurs tutoriel Android
- 17. Android premier tutoriel application
- 18. GCM ASP.NET Tutoriel Android
- 19. IndexOutOfBoundsException dans un objet BaseExpandableListAdapter implémentant SectionIndexer
- 20. Android, Drupal & DrupalCloud ou tutoriel Android-xmlrpc?
- 21. Android plus complexe Tutoriel ListView
- 22. Android température erreur tutoriel Vogella
- 23. Android: tutoriel ActivityGroup avec l'exemple
- 24. Vous cherchez OpenCV android tutoriel
- 25. Tutoriel pour les services Android?
- 26. Android Online Gaming Aide/Tutoriel
- 27. tutoriel exemple de cartes android
- 28. Android Syntaxe pendant le tutoriel
- 29. Comment faire un sectionindexer non-alphabétique
- 30. mettre tutoriel android animé pour swipepage
Je fais quelque chose de similaire ICI http://stackoverflow.com/questions/10224233/alphabetindexer-with-custom-adapter-managed-by-loadermanager – toobsco42
[cochez cette case] (http://androidcustomviews.com/portfolio-category/custom-views/) –