How to update ListView on scrolling while retrieving data from server in Android?

后端 未结 3 662
广开言路
广开言路 2021-01-31 12:46

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 swi

3条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-31 13:21

    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.

提交回复
热议问题