What is the difference between Listview and Recyclerview?

Asked

Viewed 3,271 times

13

What difference between ListView and RecyclerView on Android?

From which Api to RecyclerView is available?

It is valid to use the RecyclerView and not the ListView?

  • Who you might be interested in: using Recyclerview instead of a Gridview, at least currently, will give you a huge headache if you want the auto column size behavior (auto_fit).

2 answers

16

What a difference between Listview and Recyclerview on Android?

There are two differences between the Listview and the Recyclerview:

  1. To Recyclerview is agnostic in relation to where the views are placed, how they are moved and how this movement is animated. This is achieved by moving these responsibilities to a Layoutmanager and a Itemanimator, allowing the same Adapter visually represent the data in different ways:

    This difference is evidenced in the way each is initialized:

    • Listview:

      listView.setAdapter(myAdapter);
      
    • Recyclerview:

      recyclerView.setAdapter(myRecyclerAdapter);
      recyclerView.setLayoutManager(new LinearLayoutManager(this));
      recyclerView.setItemAnimator(new DefaultItemAnimator());
      
  2. Use a kind of Adapter(Recycler.Adapter) that implements the standard Viewholder. An object is used Viewholder to store each of the views of layout, so that they can be immediately accessed without the need to use findViewById() repeatedly.
    In the Listview that one implementation it was optional.

From which Api Recyclerview is available?

To Recyclerview came up with Android 5 but is available for earlier versions through the v7 recyclerview library.

It is valid to use Recyclerview and not Listview?

The use of any one is valid.

To Recyclerview is not exactly a substitute for Listview. It is a new, more flexible approach to providing a limited view of a large data set.

The use of Listview in immutable list situations, such as the list of options, seems perfectly appropriate.

11


Recyclerview is a new (but not so much) view that has come to replace Listview and Gridview.

According to his documentation, this is a more advanced and efficient widget, when compared to its predecessors, and it presents several simplifications to support animations and different elements provisions.

To offer all these optimizations, Google decided to simplify the element. It may sound strange, but Recyclerview has a lower level of responsibility when compared to Listview. In theory, the widget is just a container that encapsulates a Layoutmanager and an Itemanimator, and that communicates with an Adapter, more precisely, a Recyclerview.Adapter.

inserir a descrição da imagem aqui

  • But the way to have to create an Adapter, popular it, then set in Listview, remains the same pro Recyclerview?

  • Exactly, the difference is more performance even. When caching the View it is not necessary to trigger the findViewById method numerous times every time the user scrolls through the list, as a result a much more fluid list is displayed, as the cells are recycled

  • 4

    The RecyclerView requires implementation on Adapter and ViewHolder recycling of items. This is embedded in it and cannot be avoided. In ListView this paradigm is optional. It takes a little bit more work to use the RecyclerView, but is much more efficient and particularly no longer use ListView nor in trivial cases.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.