Learn Pain Less

HomeOur TeamContact
Android
Pagination in List RecyclerView using Youtube Data API Android
Pawneshwer Gupta
Pawneshwer Gupta
September 10, 2017
1 min

Table Of Contents

01
Pagination in List RecyclerView using Youtube Data API Android
02
What is pagination?
03
Why we need pagination?
04
Main Idea behind this Logic :
05
Looking for full source code of this project then fork from below link
06
Download demo APK from below link
Pagination in List RecyclerView using Youtube Data API Android

Pagination in List RecyclerView using Youtube Data API Android

Use pagination in android RecyclerView , ListView,GridView or any other list.

What is pagination?

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.

Why we need 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.

Main Idea behind this Logic :

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.

For Example :

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.

code of MainActivity.java

code of activity_main.xml

code of APIService.java

code of YoutubeApi.java

code of YoutubeResponse.java

code of VideosAdapter.java

star this repo fork this repo

Download APK

Subscribe to our newsletter!

We'll send you the best of our blog just once a month. We promise.

Tags

Retrofit 2RecyclerViewPagination

Share


Pawneshwer Gupta

Pawneshwer Gupta

Software Developer

Pawneshwer Gupta works as a software engineer who is enthusiastic in creating efficient and innovative software solutions.

Expertise

Python
Flutter
Laravel
NodeJS

Social Media

Related Posts

How to use Text To Speech inside RecyclerView in Android
How to use Text To Speech inside RecyclerView in Android
July 27, 2020
1 min
Learn Pain Less  © 2024, All Rights Reserved.
Crafted with by Prolong Services

Quick Links

Advertise with usAbout UsContact Us

Social Media