ListView vs RecyclerView

ListView vs RecyclerView

As an Android developer, Many people asked me what?s the difference between ListView and RecyclerView. In fact I myself was not aware of the differences unless I dig deep down and explored more.

Based on my experience of using both the components, I would like to place here few points which might help you understanding in a better way.

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.

As per Android developer site, RecyclerView added in version 22.1.0 and it belongs to Maven artifact com.android.support:recyclerview-v7:28.0.0-alpha1.

Image for postImage courtesy: WiseITeach

  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 the RecyclerView.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.

6. Performance on Loading

RecyclerView prepares view just ahead and behind the visible entries, which is great if you are fetching bitmaps in background. Performance is dramatically faster, especially if you use RecyclerView.setHasFixedSize. The old ListView is based on the premise that there?s no way to precalculate or cache the size of entries in the list, which causes insane complications when scrolling and performing layout. Takes a while to get used to it, but once you do, you?ll never go back

For more detailed description, You can always refer here.

You can find more details here.

That?s all now.. I know its limited content. I hope to update more details in this page soon with examples and applications.

Thanks for reading this, I hope you liked it, give a clap.

No Responses

Write a response