One way to do this is,
1) Don't populate your ArrayList with all the data. Instead keep them in a separate ArrayList (al1
) and use an ArrayList (al2
) with max 10 values to use with your BaseAdapter.
2) Initially,
- al2 = al1[0] to al1[9]
- BaseAdatper(context, data)
3) Keep the BaseAdapter as it is but change
@Override
public int getCount() {
return 10;
}
to
@Override
public int getCount() {
return data.size();
}
It's not a must but it's good practice. Now you'll be showing only 10 items cause that's all you are passing to the adapter. Also write a public function in your extended BaseAdatper class to set the data
variable.
4) On the next button click event get the next 10 items from al1
and assign to al2
. Use the public function you wrote to over write data
with al2
.
5) BaseAdapter has a method called notifyDataSetChanged , call it. What this does is tell the adapter to refresh from top to bottom. Since you have data
over written with new data when the refresh occurs you'll be seeing the new data. That's it.
I don't think it'll be difficult for you to come up with a way to keep track from which index to which in al1
you're currently displaying. :)