0

My ListView is displaying 25 items at a time and I can only download 25 items at a time from a web service that I am trying to use. Please could I have some suggestions as to how I would load the next 25 items to the List view with the option to go back to the previous ListView ( and hence the previous 25 itmes)? Is there a standard way of doing this? I have tried searching around and there appears to be nothing in the standard reference books. Many thanks.

3 Answers3

0

modify the getCount() in ListViewAdapter

FrankHong
  • 11
  • 2
0

You have three options to that actually

1) If you want that your next 25 item will load as soon as you reached the end of the ListView, so for that you have to implement an OnScrollListener, set your ListView's onScrollListener and then you should be able to handle things correctly.For example

private int preLast;
// Initialization stuff.
yourListView.setOnScrollListener(this);


 @Override
 public void onScroll(AbsListView lw, final int firstVisibleItem,
             final int visibleItemCount, final int totalItemCount) {   

        // Make your calculation stuff here. You have all your
        // needed info from the parameters of this function.

        // Sample calculation to determine if the last 
        // item is fully visible.
         final int lastItem = firstVisibleItem + visibleItemCount;
       if(lastItem == totalItemCount) {
          if(preLast!=lastItem){ //to avoid multiple calls for last item
           // load your next 25 items here
            Log.d("Last", "Last");
            preLast = lastItem;
          }
     }
}  

2) If you need that there should be a button at the end of the ListView which onClick returns next 25 items, then you should add a footer view for your ListView. For example refer this tutorial

3) You can use PullToRefresh libraries to load more data, which are easily available. One of them is here

So you can choose either of the three options whichever meets your requirements right now.

Mukesh Rana
  • 4,051
  • 3
  • 27
  • 39
0

As i understand, you want:
Currently, i fetch 25 items and then display it on my list view: OK
Then (press next, or do st), I load next my 25 items and push it into the list view :OK
Now if i go back, i want my list view display that previous data...
There are two possible way to achieve that.

Some important points to do:

  1. Load data: You may need an asyntask for this. (if not,remember the network process may block the UI and leads an Android not responding.)
  2. In your adapter, getCount() to return 25, and Call your adapter.notifyDatasetChanged() to update the data list ( may be in postExecute());
kidnan1991
  • 366
  • 2
  • 12