ANDROID RECYCLERVIEW

Android like many other mobile platforms  is able to display a large set of information to users through the small window of a phone or tablet since its inception. The Recycler view is what is used to do this since the introduction of Lollipop. It makes heavy use of a development design pattern called the Adapter Pattern and steals some elements from the commonly knownModel-View-Controller pattern to map scrolling lists of data as views on the screen. Prior to this,  ListView was used but the advantage of the recyclerview is, it is  more advanced and flexible.
What is Recyclerview?
RecyclerView is an “upgraded” version of ListView which is more advance and flexible.
RecyclerView is a container for displaying large data sets that can be scrolled efficiently by maintaining a limited number of views.
RecyclerView also provides some default animations for common item operations like inserting or removing an item.
Recyclerview Architecture
Recyclerview Architecture
Data Model -> Represents one single item in a list e.g
data model
Adapter -> Pulls the items in the data model and presents items on the screen. i.e.(Content View) via the view Holder. It’s also responsible for creating view for each item and replaces new content for the view whenever the original items is no longer visible.
ViewHolder-> it is the xml layout for the one single item inflated/converted into java code. I.e. It consists of a simple class that holds the references to the UI components all the time the system shows a row in the list.
LayoutManager -> Enables one to customize how the items will be scrolled or arranged on the screen. There are three built in LayoutManager in a recyclerview
  • LinearLayoutManager :- It lays items in a list
linear
  • GridLayoutManager :- It lays out all items in a grid
grid
  • StaggeredGridLayoutManager :- It lays out all items in a staggered grid formation, supports horizontal and vertical layouts and is able to lay out items in reverse.
staggered
  • Item Animator :- It helps one do animations on the recyclerview which was tricky and hard in a list view.
  • Item Decorator :- It  used in sectioning recyclerview into different sections.
Summary
According to the English oxford  dictionary, the word recycle means re-use and that is what the recyclerview does. An example is, when one has a list of items lets say eight on the screen, and scrolls so that one gets out, seven remain. the recycler will get that one element and then pass it to the adapter. The goal of the adapter in this case is to reuse the item number one, that is in the recycler. Instead of one having to create a new view item, this item in the recycler is pushed down to the screen as item number eight.
To use recycler view one has to declare the following dependancy:-
dependencies  {  compile ‘com.android.support:appcompat-v7:21.0.0’
compile ‘com.android.support:recyclerview-v7:21.0.+’
}
To use RecyclerView, you have to create 2 essential components:
–   LayoutManager: positions items in RecyclerView and determines when to reuse item views that are no longer visible to the user.
–   RecyclerView.Adapter: provides access to data sets items, creates views for items and binds items info to item view.

Comments

Popular Posts