Pagination with RecyclerView

Etienne Lawlor
3 min readOct 15, 2015

Almost every API we encounter as developers requires you to handle pagination. When querying an API for some resource instead of delivering all of the results, which could be time consuming and cumbersome to deal with, an API will typically make you to paginate through the results. Of course if you are trying to support pagination on a client you need to handle it gracefully.

RecyclerView

The RecyclerView is a powerful, flexible API which is deemed as the replacement to ListView, GridView, and some other ViewGroups.

It requires you to use the ViewHolder pattern which improves performance as you avoid initializing views every time.

You can decide how you want the items in your adapter to be arranged through the use of LayoutManagers.

LinearLayoutManager — supports both vertical and horizontal lists

StaggeredLayoutManager — supports Pinterest like staggered lists

GridLayoutManager — supports displaying grids as seen in Gallery apps

ItemAnimators are used to provide animations when items are added or removed from an adapter.

If you want to add margins, borders, or dividers between items in the adapter you need to set up an ItemDecorator.

--

--