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 Answers
modify the getCount() in ListViewAdapter

- 11
- 2
-
This should be your comments. Not an answer. – Zubair Ahmed Nov 07 '14 at 04:22
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.

- 4,051
- 3
- 27
- 39
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.
- You request again and then update the list view
- You store your all items in an array, and in your adapter, define the getCount() function to return 25 - the data in the list: http://developer.android.com/reference/android/widget/Adapter.html
Some important points to do:
- 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.)
- In your adapter, getCount() to return 25, and Call your adapter.notifyDatasetChanged() to update the data list ( may be in postExecute());

- 366
- 2
- 12