Blog purpose for android basic example for android app developer. any query please my contact

Tuesday, 18 May 2021

what is recyclerview in android

what is recycler view in android?

The RecyclerView is a widget that is a more flexible and advanced version of GridView and ListView. It is a container for displaying large datasets which can be scrolled efficiently by maintaining a limited number of views. You can use the RecyclerView widget when you have data collections whose elements change at runtime depend on network events or user actions.



What is a RecyclerView?

RecyclerView is the ViewGroup that contains the views corresponding to your data. It's a view itself, so you add RecyclerView into your layout the way you would add any other UI element. ... After the view holder is created, the RecyclerView binds it to its data. You define the view holder by extending RecyclerView.



Views:

The Android platform uses the View and ViewGroup classes to draw items on the screen. These classes are abstract and are extended to different implementations to suit a use case. TextView, for example, has the simple purpose of displaying text content on the screen. EditText extends from the same View class and adds more functionality to enable the user to input data.



ViewGroups:

The ViewGroup class is a kind of View but, unlike the simple View class whose responsibility is simply displaying, the ViewGroup gives us the ability to put multiple views into one view, which we can reference as a whole. In this case, the View that's created at the top level that we add other simple views(we can also add view groups) to is called the "parent," and the views that are added inside are "children".


We can image a View as an Array and a ViewGroup as an Array of Arrays. Given that an Array of Arrays is an Array itself, we can see how a ViewGroup can be treated like a View.



Implementation: To implement a basic RecyclerView three sub-parts are needed to be constructed which offer the users the degree of control they require in making varying designs of their choice.


1.The Card Layout: The card layout is an XML layout which will be treated as an item for the list created by the RecyclerView.

2.The ViewHolder: The ViewHolder is a java class that stores the reference to the card layout views that have to be dynamically modified during the execution of the program by a list of data obtained either by online databases or added in some other way.

3.The Data Class: The Data class is a custom java class that acts as a structure for holding the information for every item of the RecyclerView.




No comments:

Post a Comment