Skip to content Skip to sidebar Skip to footer

How To Update Listview On Scrolling While Retrieving Data From Server In Android?

Currently, I'm using AsyncTask to handle Http connection and retrieve data as JSON format. Loading all data is trivial but it consumes too much time, so I decided to switch to l

Solution 1:

Solution 2:

A typical approach would be e.g. to load 25 initially and then have a footer in the list that displays e.g. the current count and the total count and upon pressing loads another 25 and so on. That would be a paged sort of loading.

When you do that you have to keep the current position and notify the adapter that the list has changed.

Solution 3:

If you are using a ListView, I believe I can safely assume that you must be using some sort of ListAdapter. Instead of starting a new AsyncTask in the onScroll event, you should maintain just one single AsyncTask to retrieve data from the server, add that data to the ListAdapter dataset and then call notifyDatasetChanged on the ListAdapter.

The ListAdapter and ListView will take care of the rest.

Post a Comment for "How To Update Listview On Scrolling While Retrieving Data From Server In Android?"