Quiero hacer algunas cosas. Quiero hacer cargas perezosas en ListView
. Mi ListView
contiene más de 10,000 datos & solo en TextView
. entonces no puedo cargar todos esos datos en la primera vez cuando inicio la actividad de la lista. no es eficiente así que puedo cargar primero 20 o 30 artículos en la lista. Además, las filas del ListView
se cargan cuando me desplazo sobre ellas. entonces cuando alcanzo el último índice de ListView
en el último índice, pondré progressbar n notará que los datos nuevos están cargados, entonces en ese momento los nuevos datos se cargarán con el último + 1 índice. ¿Cómo puedo hacer esto?Android listview lazy loading
Respuesta
Puede lograr esto mediante el uso de la implementación del adaptador sin fin. Esto hace exactamente lo que quieres. También puede restringir el número de filas que se actualizarán por desplazamiento. Aquí hay un enlace a la misma.,
Android: Implementing progressbar and "loading..." for Endless List like Android Market
https://github.com/commonsguy/cwac-endless
Para usarlo, se amplía EndlessAdapter para proporcionar detalles acerca de cómo manejar la infinitud. Específicamente, debe ser capaz de proporcionar una vista de fila, independiente de cualquiera de las filas en su adaptador real, que servirá como un marcador de posición mientras que, en otro método, carga los datos reales en su adaptador principal. Luego, con un poco de ayuda de usted, transiciones sin problemas en los nuevos datos.
Gracias amigo, déjame probar este. – Jai
¡El enlace está roto ahora! :( –
// ponga en función de llamar:
@Override
public View onCreateView(android.view.LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
ScrollListener scrollListener = new ScrollListener();
listView.setOnScrollListener(scrollListener);
}
y clase interna:
class ScrollListener implements OnScrollListener
{
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount)
{
int size = searchedPeople.size();
if(isScrolled && totalItemCount != 0 && size < totalPeoples)
{
if(firstVisibleItem + visibleItemCount >= totalItemCount)
{
yourfunction(size, size + limit); // call service in your functioin
isScrolled = false;
}
}
}
@Override
public void onScrollStateChanged(AbsListView view, int scrollState)
{
}
}
hacer listas de desplazarse más rápido: -
- Reducir el número de condiciones utilizado en el
getView
de su adaptador. - Reducir el número de advertencias de recolección de basura que se obtienen en los registros de
- función Add desplazamiento (restringir el número de filas que se actualice por desplazamiento)
Añadir un onScrollListener a la ListView. Cuando el usuario se desplaza, verifique si el ListView está llegando a su final. Si es así, entonces obtenga más datos. A modo de ejemplo:
public abstract class LazyLoader implements AbsListView.OnScrollListener {
private static final int DEFAULT_THRESHOLD = 10 ;
private boolean loading = true ;
private int previousTotal = 0 ;
private int threshold = DEFAULT_THRESHOLD ;
public LazyLoader() {}
public LazyLoader(int threshold) {
this.threshold = threshold;
}
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
if(loading) {
if(totalItemCount > previousTotal) {
// the loading has finished
loading = false ;
previousTotal = totalItemCount ;
}
}
// check if the List needs more data
if(!loading && ((firstVisibleItem + visibleItemCount) >= (totalItemCount - threshold))) {
loading = true ;
// List needs more data. Go fetch !!
loadMore(view, firstVisibleItem,
visibleItemCount, totalItemCount);
}
}
// Called when the user is nearing the end of the ListView
// and the ListView is ready to add more items.
public abstract void loadMore(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount);
}
Actividad:
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_layout);
ListView listView = (ListView) findViewById(R.id.listView);
listView.setOnScrollListener(new LazyLoader() {
@Override
public void loadMore(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
// Fetch your data here !!!
}
});
}
}
Puede encontrar la aplicación completa at this link
- 1. Lazy Loading with Ninject
- 2. Lazy Loading en Flexslider
- 3. ¿Qué es Lazy Loading?
- 4. jQuery Cycle Lazy Loading
- 5. jQuery Infinite Scrolling/Lazy Loading
- 6. cuándo usar Lazy loading/Eager loading en hibernate?
- 7. entidad Código Marco Primera Lazy Loading
- 8. EF 4 - Lazy Loading Sin Proxies
- 9. Spring, @Transactional e Hibernate Lazy Loading
- 10. LINQ a las entidades y Lazy Loading
- 11. JSON.NET y NHibernate Lazy Loading Colecciones de
- 12. Lazy Load images on Listview in android (Beginner Level)?
- 13. DataTable - Lazy Loading Primefaces que muestra el error
- 14. JPA - Force Lazy loading solo para una consulta dada
- 15. Lazy Loading UIImages de archivos sin bloquear el hilo principal?
- 16. Android Async Data Loading Methods
- 17. ¿Cómo desactivo Lazy Loading, Entity Framework 4.1 utilizando código de Migraciones de configuración
- 18. Spring @Autowired @ Lazy
- 19. android ListView scrollbarStyle
- 20. Android ListView Selección Problema
- 21. Android setbackgrounddrawable listview
- 22. Temas de Android ListView
- 23. Personalizar Android ListView Colors?
- 24. android checkable listview
- 25. Android: EditText en ListView
- 26. android - índice para ListView?
- 27. Android ListView Headers
- 28. Android deshabilitar elementos listview
- 29. Android ListView Seleccionar animación
- 30. Edittext en Listview android
podría mostrar lo que usted ha intentado? – gideon
ya he agregado una imagen aquí como ejemplo ... compruebe este – Jai
¿Qué tal picasso? ¿Esto satisface tu necesidad? http://square.github.io/picasso/ – phi