0

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!

Umang
  • 583
  • 2
  • 12
  • 28

2 Answers2

1

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)?

Community
  • 1
  • 1
Pratik
  • 30,639
  • 18
  • 84
  • 159
  • thanks for the links.. I cant vote up as I am new to stackoverflow and do not have enough reputation. Will definitely do that in future :) – Umang Sep 13 '11 at 07:02
0

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.

David Olsson
  • 8,085
  • 3
  • 30
  • 38
  • can you please provide with a full working code for your example? that would really be helpful! – Umang Sep 13 '11 at 07:01
  • Not really since I am not going to do the work for you and probably noone else will do that here on stackoverflow. I just had listview.setonScrollListener(this) and then implemented the onScrollListener. The fetchclass you have to do yourself since it depends on your webservice. – David Olsson Sep 13 '11 at 07:06