1
Write a post

What is RecyclerView? And how to use it?

Published Apr 19, 2017

With the advent of Android Lollipop, the RecyclerView made its way officially. The RecyclerView is much more powerful, flexible and a major enhancement over ListView. below is detailed insight into it.

1) ViewHolder Pattern

In a ListView, it was recommended to use the ViewHolder pattern but it was never a compulsion. In case of RecyclerView, this is mandatory using the RecyclerView.ViewHolder class. This is one of the major differences between the ListView and the RecyclerView.

It makes things a bit more complex in RecyclerView but a lot of problems that we faced in the ListView are solved efficiently.

2) LayoutManager

This is another massive enhancement brought to the RecyclerView. In a ListView, the only type of view available is the vertical ListView. There is no official way to even implement a horizontal ListView.

Now using a RecyclerView, we can have a

i) LinearLayoutManager – which supports both vertical and horizontal lists,

ii) StaggeredLayoutManager – which supports Pinterest like staggered lists,

iii) GridLayoutManager – which supports displaying grids as seen in Gallery apps.

And the best thing is that we can do all these dynamically as we want.

3) Item Animator

ListViews are lacking in support of good animations, but the RecyclerView brings a whole new dimension to it. Using the RecyclerView.ItemAnimator class, animating the views becomes so much easy and intuitive.

4) Item Decoration

In case of ListViews, dynamically decorating items like adding borders or dividers was never easy. But in case of RecyclerView, the RecyclerView.ItemDecorator class gives huge control to the developers but makes things a bit more time consuming and complex.

5) OnItemTouchListener

Intercepting item clicks on a ListView was simple, thanks to its AdapterView.OnItemClickListenerinterface. But the RecyclerView gives much more power and control to its developers by theRecyclerView.OnItemTouchListener but it complicates things a bit for the developer.

In simple words, the RecyclerView is much more customizable than the ListView and gives a lot of control and power to its developers.

Discover and read more posts from Kuldeep Joshi
get started
Enjoy this post?

Leave a like and comment for Kuldeep

2
Be the first to share your opinion

Get curated posts in your inbox

Learn programming by reading more posts like this