Reputation: 593
I am working on an app where I need to display a lot of data in a list, say 100 items. I was thinking of implementing it like facebook app does, progressively loading all the data once the user scrolls down to the bottom of list. Can anyone help me on this? Also, if this doesnt work, Can you suggest some ideas of implementing this? One thing I thought was putting the Load more option in the menu and then iteratively calling for more data.
Thanks!
Upvotes: 0
Views: 2738
Reputation: 8225
You should use onScrollListener and depending on how many items that are left you load more. IE by calling the webservice with index numbers, start and end.
Here is an example I have used: In this example I always fetch the next 15 items from the server. and the first if case is that it starts fetching new items when there is only x number of items left. X is 2* the number of visisble items on the screen. It depends on the screen density.
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
if((totalItemCount-(firstVisibleItem+visibleItemCount) <= visibleItemCount*2)) {
startNumber = totalItemCount;
endNumber = startNumber+15;
if(fetchclass!=null) {
if(!fetchclass.isRunning()) {
fetchclass= new fetchNewsClass();
fetchclass.execute(startNumber,endNumber);
}
}
else {
fetchclass = new fetchNewsClass();
fetchclass.execute(startNumber,endNumber);
}
}
}
startNumber and endNumber is just index numbers that I use to call the webservice to get the correct data from the server. fetchclass is the AsyncTask that I use to fetch the data.
Upvotes: 0
Reputation: 30855
You can use the LazyLoading concept or AsyncTask class for background process concept.
here are the links
http://developer.android.com/reference/android/os/AsyncTask.html
http://www.xoriant.com/blog/mobile-application-development/android-async-task.html
http://androidsnips.blogspot.com/2010/08/lazy-loading-of-images-in-list-view-in.html
Lazy load of images in ListView
Lazy Load images on Listview in android(Beginner Level)?
Upvotes: 1