+ Reply Thread
#1
RecyclerView:
A view previously used to display data to a specific adapter position may be placed in a cache for later reuse to display same type of data again later.
This can drastically improve performance by skipping initial layout inflation or construction.
Implementing RecyclerView is fun ones you understand how the various part are coupled together, today i will be showing you guys how it works.
How it works.
The RecyclerView Api contains an generic adapter class, which accepts a subclass or the RecylcerView.Viewholder class as its parameter.
  • An Adapter:
    This can be said to be a layer, medium or channels through which datas(Objects,datatypes e.t.c) is being passed to their respective views, using layouts(A form of containers for views) to directly position and measure them appropriately.
  • ViewHolder:
    As the name implies its a container for holding views references(Addresses to different view types used by the Adapter).
    This references most be written inside the ViewHolder for views to respond to data parsed into it from the adapter.
    Here in this example the ViewHolder serves as an innerclass class for the Adapter class we will be using.
  • onBindViewHolder:
    Its an Abstract method use to bind the views supplied by the ViewHolder Class instance variable to their respective datas.
    Here we use PoJo(plain old java objects) as a scheme to supply the datas to each respective views.
  • onCreateViewHolder:
    Its an Abstract method with a return type of ViewHolder.
    Its use to inflate(populate and instantiante) the layout we will be creating from xml, with the individuals views we declared via the ViewHolder.
  • getItemCount():
    Its an Abstract method use to get the size of the datas we will be giving the adapter from the ArrayList(Arraylist is a more dynamic form of array, that is used to store object types, it also internally convert primitive types to object types before use).
  • LayoutManager:
    LayoutManager is container having different subclasses, that is used to manage,measure and positions views in an android form(layout).
    we have the LinearlayoutManager,GridlayoutManager as subclass of the LayoutManager.
How They are Coupled Together:
The adapter receives the datas supplied to it via the activity(User interface) by the Arraylists.
The Arraylists accepts the datas from the PoJo, and in turn supply it to the adapter. The Adapter populate the datas to the views using the Viewholders inner class object, This feeds the datas to the views.
The Adapter then parsed the data to the recyclerview instance in the MainActivity using the setAdapter method of the RecyclerView class,The RecyclerView which has already been configured with a layoutmanager, in our case the LinearLayoutManager.
The LinearLayoutManager position and measures its view apporpriately and ..........Wola...
Thats it.
Now lets implement it in Android Studio, create a new project.
Lets First Add the following dependency to our app to gradle file.
Code:
compile 'com.android.support:recyclerview-v7:25.3.1' compile 'com.android.support:cardview-v7:25.3.1'
After placing them Sync your project.
cardview support is needed to add beauty to our views layout.
Now lets create our layout for views. Thats It For today.
comments if you are interested, and i will post the remaining part of the tutorial.
#2
bring it on .
#3
What's first to note about developing an Android app? What tools are needed and how does one configure the IDEs? What programming language is used in coding on Android??? I'm just so lost in here :'(
Back to top