-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Welcome to the IssueTrackerUsingVolly wiki!
The RecyclerView was introduced with Google’s material design in Android 5.0 Lollipop.
If you are getting started with Android development or are already an experienced developer the RecyclerView is something worth investigating.
The idea of view recycling has been in Android since version 1 in the form of the ListView. The idea is simple, to present large collection of data using a small collection of views, by recycling and rebinding these views.
The RecyclerView is a more flexible pattern of view recycling than ListViews and GridViews.
Required ViewHolder in Adapters - ListView adapters do not require the use of the ViewHolder pattern to improve performance. In contrast, implementing an adapter for RecyclerView requires the use of the ViewHolder pattern. Customizable Item Layouts - ListView can only layout items in a vertical linear arrangement and this cannot be customized. In contrast, the RecyclerView has a RecyclerView.LayoutManager that allows any item layouts including horizontal lists or staggered grids. Easy Item Animations - ListView contains no special provisions through which one can animate the addition or deletion of items. In contrast, the RecyclerView has the RecyclerView.ItemAnimator class for handling item animations. Manual Data Source - ListView had adapters for different sources such as ArrayAdapter and CursorAdapter for arrays and database results respectively. In contrast, the RecyclerView.Adapter requires a custom implementation to supply the data to the adapter. Manual Item Decoration - ListView has the android:divider property for easy dividers between items in the list. In contrast, RecyclerView requires the use of a RecyclerView.ItemDecoration object to setup much more manual divider decorations. Manual Click Detection - ListView has a AdapterView.OnItemClickListener interface for binding to the click events for individual items in the list. In contrast, RecyclerView only has support for RecyclerView.OnItemTouchListener which manages individual touch events but has no built-in click handling. Components of a RecyclerView
A RecyclerView needs to have a layout manager and an adapter to be instantiated. A layout manager positions item views inside a RecyclerView and determines when to reuse item views that are no longer visible to the user.
RecyclerView provides these built-in layout managers:
shows items in a vertical or horizontal scrolling list.
shows items in a grid.
shows items in a staggered grid. To create a custom layout manager, extend the RecyclerView.LayoutManager class.
RecyclerView includes a new kind of adapter. It’s a similar approach to the ones you already used, but with some peculiarities, such as a required ViewHolder. ItemAnimator
RecyclerView.ItemAnimator will animate ViewGroup modifications such as add/delete/select that are notified to adapter
Using a RecyclerView has the following key steps:
Add RecyclerView support library to the gradle build file Define a model class to use as the data source Add a RecyclerView to your activity to display the items Create a custom row layout XML file to visualize the item Create a RecyclerView.Adapter and ViewHolder to render the item Bind the adapter to the data source to populate the RecyclerView
RecyclerView is very similar to the ListView and we can use them in the same way:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MyActivity">
<android.support.v7.widget.RecyclerView
android:id="@+id/cardList"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</RelativeLayout>
Need to Add dependancy in build.gradle compile 'com.android.support:recyclerview-v7:23.2.1'