Why RecyclerView? What is the difference between ListView and RecyclerView in Android?

In Android, we can create a scrolling list either using a listView or a recyclerView. So in this blog, we’re going to discuss 5 major differences between the listView and recyclerView which every android developer should know.

Before going to discuss the differences between ListView and RecyclerView, let’s see what are ListView and RecyclerView?

ListView and RecyclerView — a brief history

Until Android Lollipop release, we mostly used the ListView widget in most of the applications and it wasn’t that bad. But unfortunately, it allows us to create just the row-scrolling list of elements and, to make that list scrolling go smoothly, we have to remember to do it correctly. Whenever we have to handle the listView, the only way to handle it through the ListView object itself or inside the adapter class, which make the ListView class bit too heavy.

But now we use the RecyclerView, which was introduced with the Android Lollipop and it proved to be a game-changer. It fixed a lot of problems that we faced in the ListView. By default, it is more efficient, the layout is separated and, we have more chances over the data set inside the adapter.

If you want to know more about RecyclerView, you can take a look at my article which shows how to implement a RecyclerView.

Now, let’s discuss the differences between ListView and RecyclerView.

ListView vs RecyclerView — differences

1. ViewHolder

The RecyclerView’s adapter makes us use the ViewHolder method. The creating part (inflating the layout and finding views) and updating the views divided into two methods — onCreateViewHolder() and onBindViewHolder().

On the other hand, the listview doesn’t give us that kind of functionalities, so without using the ViewHolder method inside the getView() method we’ll end up with an inefficient scrolling list.

2. LayoutManager

For example, if we want to scroll our list vertically or horizontally, we can choose LinearLayoutManager. For grids, it is more suitable to choose GridLayoutManager.

Earlier, with the use of the ListView, we were only able to create a vertical-scrolling list, so it wasn’t that flexible. For grids on our list, we had to choose the GridView widget for that.

3. ItemDecoration

For example, if we want to add the divider between the rows of the recyclerView, we need to use the DividerItemDecoration and add it to the RecyclerView.

But in the ListView, we have to figure out rows of decorations by ourselves. There is no helper class like ItemDecoration for this widget.

4. ItemAnimator

RecyclerView ItemAnimator is smooth and nice. We can change it by creating our own ItemAnimator, which is also not easy. To use it, we should extend the SimpleItemAnimator class and implement the methods that we need (just add animations to a ViewHolder’s views).

But in the case of ListView, we need to figure it out by ourselves and it is not easy.

5. Notifying adapter

Using ListView, we were able to use just notifyDataSetChanged() on the adapter and then had to handle the rest ourselves, again.

Wrap up

Luckily, the RecyclerView was introduced and a lot of problems were solved. It’s more efficient by default, its animations are simpler, arranging the layout is becoming easier, and the API is much nicer. So, if you ever question which one you should choose, your first consideration should be the RecyclerView. I hope this article helped you to understand what is the difference between ListView and RecyclerView

And for content like this visit GBAndroidBlogs

Happy Coding!!

Hi everyone, myself Golap an Android app developer with UI/UX designer.