Does Android dynamically load Listview at end of scroll?

I load the list from the Http server, 20 at a time, At the end of Listview I want to download the next 20 data from the server , and this process will continue until the data ends on the server, I used a class that extends the BaseAdapter to populate the first 20 data. What should I do?

+62
android
Feb 21 '11 at 11:23
source share
6 answers

It also looks like an elegant solution: http://benjii.me/2010/08/endless-scrolling-listview-in-android/

It also implements AbsListView.OnScrollListener and uses AsyncTask to load more content once a certain threshold of the remaining elements in the current scroll view is reached.

+42
Mar 11 2018-11-11T00:
source share

Ok, I saw that this is a common problem, so I made a LITTLE LIBRARY with additional downloads and pulled out to update the ListView on github , please check this in here , all this is explained in the repository.

+19
Jan 24 2018-12-12T00:
source share

You can implement AbsListView.OnScrollListener , which receives information and which allows you to load more data.

Cm.

 .... ListView.setOnScrollListener(this); .... 

And then look at https://github.com/pilhuhn/ZwitscherA/blob/master/src/de/bsd/zwitscher/TweetListActivity.java#L287

Or look at List9 example from sdk examples.

+10
Feb 22 '11 at 6:52
source share

Heiko Rupp code is the best option for this problem. The only thing you need to do is implement onScrollListener and in onScroll() just check if there is an end to the list using code

 boolean loadMore = firstVisibleItem + visibleItemCount >= totalItemCount-1; 

if true loads your data in the usual way.

thaks Heiko Rupp for this snippet :)

+8
Aug 22 2018-11-21T00:
source share

This is what I used to load more data at the end of the list.

  listview.setOnScrollListener(new OnScrollListener(){ @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { //Algorithm to check if the last item is visible or not final int lastItem = firstVisibleItem + visibleItemCount; if(lastItem == totalItemCount){ // you have reached end of list, load more data } } @Override public void onScrollStateChanged(AbsListView view,int scrollState) { //blank, not using this } }); 
+7
Oct. 16 '13 at 19:13
source share

I had this problem when I accidentally tried to update a view from a non-user thread. Moving the UI update code to the UI thread solved my problem!

 Handler mainHandler = new Handler(Looper.getMainLooper()); mainHandler.post(new Runnable() { @Override public void run() { // insert ui update code here } } }); 
0
Jan 19 '18 at 16:30
source share



All Articles