With the android L preview version, Google has introduced two new Widgets , RecyclerView and CardView the first, the RecyclerView .
This new Widget comes into play when the purpose is to show large number of Views repeatedly, lists, grids, etc ..., so many that do not enter the screen.
RecyclerView implements a system to carry out this task, simply and efficiently.
The RecyclerView API
Unlike the ListView , GridView , etc ... the RecyclerView is dedicated only to what its name indicates, recycle, reuse resources and avoid use reiterated from the expensive findViewById, does not care about the visual aspect, for it is the LayoutManager,
A class a task, that is the philosophy that follows the API of the RecyclerView, a package of internal classes each with a responsibility:
This class is responsible for creating the necessary Views for each element of the RecyclerView , in addition, it is closely linked to the ViewHolder, having to be indicated in the class declaration, many think that this is not new, that Google already advised this pattern time ago, this time force to use it, having to be indicated in the implementation of the Adapter, a step forward, no doubt.
The ViewHolder pattern is nothing new, in fact Google, it has been recommending for a long time, you can think of it as a view cache, being able to reuse them instead of creating them again.
The LayoutManager takes care of the layout of all the views within the RecyclerView, specifying with the LinearLayoutManager, it allows, among others, access elements displayed on the screen as the first, last, or last element completely visible, this horizontally or vertically, in the example the vertical layout has been used.
Another important link, are called ItemDecorator , these allow to modify the elements of the RecycleView, this in addition, offers also offers an element called insets (margins) that can be applied to the views without having to modify the parameters of the layout.
The ItemAnimator class as the name implies, encourages the RecyclerView when an item is added and deleted, the RecyclerView uses an ItemAnimator by default.
The RecyclerView should know when an item is inserted or deleted, with items like ListViews, GridViews, etc ... this was achieved by calling the notifyDataSetChanged () method, at performance level, it is quite expensive, since which redraws all items in the layout, the same with the RecyclerView is to use the notifyItemInserted () method to add, and notifyItemRemoved () to delete, updating only the appropriate part.