Use pagination in android RecyclerView , ListView,GridView or any other list.
Pagination means load data in some chunks called as pagination. For example load 100 items in 10 parts having 10 item each, called as pagination.
If you are loading 10,000 items from Web API or local database then it will take more time to fetch data from Web API and display them in List. So its better to display first 10 items, and if user want to view more then load 10 more and so on. This will increase load time of data and performance of app too.
In this example I’m using Youtube Data API, you can use any API which you preffer. And I’m using RecyclerView to display items, you can use ListView or GridView too.
In Youtube API we get token (String) of next list, so we will pass that token while requesting next data call. But first time we will pass empty value as token so it will return latest items.
But if you want to use Pagination in your own web API then ask your Backend developer to add 2 request parameters “start” and “limit”. And return “last_index” along with data. “start” parameter will be used to fetch data from “start” index and “limit” parameter will be used to max number of data.
if you pass 0 as “start” and 10 as “limit” parameter then API will return data from 0 to 10 items. And now in next call pass “last_index + 1” as start parameter. So now you will pass 11 as “start” and 10 as “limit” and you will get data from 11 to 20 and so on.
Now when you get data from Web API then add that data to adapter of RecyclerView, ListView or GridView. You can also replace data of Adapter if you want to display only new items.
Quick Links
Legal Stuff
Social Media