What is the Recyclerview?

Asked

Viewed 302 times

9

I saw the class at documentation of Andorid, but I did not understand its functionality, where it should be used and with what purpose. The name referred me to something that doesn’t seem to be what it actually represents.

Is there anything on other platforms that behaves similarly for me to try to see better?

  • 1
  • I’m convinced I’ve seen an identical question around, but I can’t find it. Anyway I find the question very relevant

  • I didn’t think so, but if there’s one there ;)

  • 2

    For me the name is very applicable. Recycle of Reciclar, which is what he does with the views. It reuses the cells.

  • 1

    I find this link very interesting: https://imasters.com.br/android/listas-recyclerview

1 answer

9


Recyclerview is a view which allows displaying a part of a large data set.

She resorts to several classes, namely to the Recyclerview.Adapter, Recyclerview.Layoutmanager and Itemanimator.

The function of Recyclerview.Adapter is to "take" the data, coming from any data source, and "transform" it into views to be shown by Recyclerview.

Manage the form/layout in which this set of views is displayed is the responsibility of Recyclerview.Layoutmanager.

Itemanimator allows animating items when they are moved.

Delegating this responsibility allows Recyclerview to display the same set of data in different ways. Not only how each item’s data(field) is displayed, but also the layout of each item as a whole: vertical or horizontal list, uniform grid or stggered, or in any other form.

I think the name is due to the implementation of Recyclerview.Adapter force that views no longer used are reused when necessary.
This is achieved with the methods onCreateViewHolder() and onBindViewHolder().

  • When a new set of views, the method onCreateViewHolder() is called followed by onBindViewHolder().
  • If any views available, only is called the method onBindViewHolder().

On the other hand it requires the implementation of "Default View Holder", where an object Recyclerview.Viewholder is used to "store" references to views, avoiding the repeated use of the method findViewById().

Note that both Listview and Gridview enable the reuse of views and the implementation of the "View Holder Standard", however its implementation is optional.

In several publications I have seen her presented as a substitute for Listview. In my opinion it is more than that: it is a new approach, more flexible, structured and with greater performance, to display a limited view of a large data set.

  • Flexible, because it uses customizable external objects.
  • Structured, because it explicitly requires the reuse of views and the implementation of the View Holder Standard.
  • Performance, in addition to the reuse of views and standard View Holder, allows selective updating of items, preventing the entire old dataset from being replaced by the new dataset. Only modified/deleted/inserted items are updated.

I use Recyclerview when I want to take advantage of what it offers: performance, layout and tailor-made animations. In "simpler" cases, with little data and not subject to change, I use Listview or Gridview, but always implement the Viewholder standard.

As a complement see:

Is there anything on other platforms that behaves similarly for me to try to see better?

Browser other questions tagged

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