¿Crea desplazamiento alfabético fácil en ListView?
Estoy buscando para emular la funcionalidad en la última aplicación de música, es decir, el pequeño cursor agradable que aparece lo que permite desplazarse muy rápido al artista / álbum / pista que están buscando:
- Pase el evento de movimiento a la Scrollview primaria cuando Listview en la parte superior / inferior
- cómo agregar varias vistas de imagen en la fila de vista de lista con vista de desplazamiento horizontal
- agregar clic Listner en cada elemento de fila en ListView
- Android: Cómo ocultar un elemento ListView
- Vistas de varias listas de Android que no se desplazan de forma independiente
¿Existe un método para habilitar funcionalidades como esta en un ListView
en el SDK de Android?
- Android StaggeredGridView dentro de la altura de ListView
- Cómo restablecer listview después de searchview se cierra en android?
- ¿Saber cuándo una vista en un ListView ha salido de la pantalla?
- Android: ¿Los elementos de las listas no se vuelven naranjas cuando se hace clic?
- ¿Cómo afectar a elementos fuera de un listview cuando se hace clic en algunos elementos de la vista de lista?
- ¿Cómo actualizar ListView en ListFragment de FragmentActivity?
- Recyclerview de Android vs ListView con el usuario
- TextView en las filas listview que muestran valores repetidos en desplazamiento en Android?
Haga que su adaptador de lista implemente SectionIndexer . La aplicación de música también hace uso de AlphabetIndexer para hacer algunos de los trabajos pesados. También use setFastScrollEnabled(true)
en el ListView
actual para habilitarlo.
Editar : Si no está utilizando un CursorAdapter, no podrá utilizar AlphabetIndexer. Usted podría tratar de ver la implementación aquí y ver lo difícil que sería adaptarlo para trabajar con un ArrayAdapter.
Esta es la subclase de ArrayAdapter que estoy usando. Tenga en cuenta que los objects
que paso ya han sido ordenados alfabéticamente, con Collections.sort(objects)
.
class SectionIndexingArrayAdapter<T> extends ArrayAdapter<T> implements SectionIndexer { HashMap<String, Integer> sectionsMap = new HashMap<String, Integer>(); ArrayList<String> sectionsList = new ArrayList<String>(); ArrayList<Integer> sectionForPosition = new ArrayList<Integer>(); ArrayList<Integer> positionForSection = new ArrayList<Integer>(); public SectionIndexingArrayAdapter(Context context, int textViewResourceId, List<T> objects) { super(context, textViewResourceId, objects); // Note that List<T> objects has already been sorted alphabetically // eg with Collections.sort(objects) **before** being passed to // this constructor. // Figure out what the sections should be (one section per unique // initial letter, to accommodate letters that might be missing, // or characters like ,) for (int i = 0; i < objects.size(); i++) { String objectString = objects.get(i).toString(); if (objectString.length() > 0) { String firstLetter = objectString.substring(0, 1).toUpperCase(); if (!sectionsMap.containsKey(firstLetter)) { sectionsMap.put(firstLetter, sectionsMap.size()); sectionsList.add(firstLetter); } } } // Calculate the section for each position in the list. for (int i = 0; i < objects.size(); i++) { String objectString = objects.get(i).toString(); if (objectString.length() > 0) { String firstLetter = objectString.substring(0, 1).toUpperCase(); if (sectionsMap.containsKey(firstLetter)) { sectionForPosition.add(sectionsMap.get(firstLetter)); } else sectionForPosition.add(0); } else sectionForPosition.add(0); } // Calculate the first position where each section begins. for (int i = 0; i < sectionsMap.size(); i++) positionForSection.add(0); for (int i = 0; i < sectionsMap.size(); i++) { for (int j = 0; j < objects.size(); j++) { Integer section = sectionForPosition.get(j); if (section == i) { positionForSection.set(i, j); break; } } } } // The interface methods. public int getPositionForSection(int section) { return positionForSection.get(section); } public int getSectionForPosition(int position) { return sectionForPosition.get(position); } public Object[] getSections() { return sectionsList.toArray(); } }
SetFastScrollEnabled (true);
( http://developer.android.com/reference/android/widget/AbsListView.html )
En anddev.org encontré este tutorial: Alphabetic FastScroll ListView – similar a los contactos
También contiene una breve demo-video
¡Espero eso ayude!
Para recopilar los detalles sobre los elementos mostrados en una vista de lista, puede hacer esto:
@Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { albumButton.setText(songs.get(firstVisibleItem).getAlbum()); }
¿No es esto un poco más simple? Aquí, "canciones" es un arraylist de objetos de la canción. Incluso puede obtener el último elemento visible añadiendo firstVisibleItem + visibleItemCount. He encontrado esta técnica muy útil. Así que usted obtendría la primera letra de cada canción. Supongo que el cuadro gris que contiene la letra en la aplicación de música que publicó es un cuadro de diálogo de las clases?
De todos modos, espero que esto ayude. Me doy cuenta que llego tarde, pero esto es para gente futura
He encontrado una gran solución aquí … Funciona muy bien con una lista enorme … Agradable y rápido … sin tiempo de carga.
@Override public int getPositionForSection(int section) { log.info("Get position for section"); for (int i = 0; i < this.getCount(); i++) { if (this.getItem(i).length() > 0) { String item = this.getItem(i).toUpperCase(); if (item.charAt(0) == sections.charAt(section)) { return i; } } } return 0; } @Override public int getSectionForPosition(int arg0) { log.info("Get section"); return 0; } @Override public Object[] getSections() { log.info("Get sections"); String[] sectionsArr = new String[sections.length()]; for (int i = 0; i < sections.length(); i++) { sectionsArr[i] = "" + sections.charAt(i); } return sectionsArr; }
- ¿Cómo crear el diseño de una vista personalizada de forma programática?
- Android – Temas de aplicaciones personalizadas que están disponibles gratuitamente