Should We Use Recyclerview to Replace Listview

RecyclerView vs. ListView

RecyclerView was created as a ListView improvement, so yes, you can create an attached list with ListView control, but using RecyclerView is easier as it:

  1. Reuses cells while scrolling up/down - this is possible with implementing View Holder in the ListView adapter, but it was an optional thing, while in the RecycleView it's the default way of writing adapter.

  2. Decouples list from its container - so you can put list items easily at run time in the different containers (linearLayout, gridLayout) with setting LayoutManager.

Example:

mRecyclerView = (RecyclerView) findViewById(R.id.my_recycler_view);
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
//or
mRecyclerView.setLayoutManager(new GridLayoutManager(this, 2));

  1. Animates common list actions - Animations are decoupled and delegated to ItemAnimator.

There is more about RecyclerView, but I think these points are the main ones.

So, to conclude, RecyclerView is a more flexible control for handling "list data" that follows patterns of delegation of concerns and leaves for itself only one task - recycling items.

When to use ListView instead of RecyclerView


is the RecyclerView meant to replace ListView?

Yes.

Do I have to replace all my ListViews with RecyclerViews?

No.

What I don't get is when to use ListView and when to use RecyclerView.

My recommendation is to use only RecyclerView for lists going forward. It is meant as a replacement for ListView, and it is a fantastic one at that. I would expect RecyclerView to continue to receive updates, but ListView will likely remain more or less as it is right now.

ListView isn't going anywhere because there are far too many applications that use it. Google can't just remove it because that would prevent most existing apps from compiling with the latest SDK. Deprecating it also isn't ideal because converting a ListView to a RecyclerView is a non-trivial amount of work and there isn't anything particularly broken with ListView.

Should I change the existing Listview in my app to RecyclerView?

That's a tough question to answer. First of all: Think of the RecyclerView as the successor of the AdapterViews which comes with alot of useful improvement especially in the fields of animations for each item. Actually that's also what the Docs say:

RecyclerView is a more advanced and flexible version of ListView. This
widget is a container for large sets of views that can be recycled and
scrolled very efficiently. Use the RecyclerView widget when you have
lists with elements that change dynamically.

You also have the flexibility to define custom layout managers and
animations for this widget.

So in the future we'll probably don't use ListViews anymore. Furthermore the RecyclerView doesn't need anything like "notifyDataSetChanged()" when an item is added or deleted from your List, which is a huge improvement performance-wise.

If you wanna know more what Google means by saying "more advanced and flexible version of ListView" I'd recommend you to read this Blog-Post A First Glance at Android’s RecyclerView.

But to answer your questions explicity:

Is there any advantages of converting the existing Listview in my app to RecyclerView?

Yes. As already said the RecyclerView is much more flexible and comes with handy animations at no cost. (In terms of doing this on your own)

When should I be using RecyclerView?

Everywhere where a ListView is appropriate a RecyclerView is as well.

And an additional question:

Is it necessary to switch from ListView to RecyclerView?

At the moment absolutely not! You have to consider that the RecyclerView isn't final at this point. So there may be some changes, bug-fixes and new features in the near future.
(As an example for a bug: clipToPadding doesn't work atm. Luckily it has been reported already)

Do I need to use list view inside recyclerView or recyclerView inside recyclerView?

Don't use ListView anymore, because it has been replaced by RecyclerView. I don't understand, why do you need to use RecyclerView inside RecyclerView?

If you paragraph is not very long, you can just use TextView inside a ScrollView.

If you paragraph is very long, you can use RecyclerView and use TextView as the View for the line item. Since RecyclerView use ViewHolder pattern, it will good for performance.



Related Topics



Leave a reply



Submit