Introduction
The Recycler View is used to display a group of messages, songs, images (Ex: Inbox, music player, Gallery). For more details, Click.
Let’s start,
Step 1: Open Visual Studio->New Project->Templates->Visual C#->Android->Blank App.
Select Blank App. Then, give Project Name and Project Location.

Step 2
Next, go to Solution Explorer-> Project Name-> Components. Right click on Get More Components. This opens a new dialog box. In this dialog box, search for the Recycler. Now, add the Android Support Library V7 RecyclerView packages.

Step 3
Next, we need to create New Layout for Contact List View. Go to Solution Explorer-> Project Name->Resources->layout. Right click on Add-> New Item; opens a new dialog box. Select Android Layout and name it as ContactLayout.axml.

Step 4
We need to store the contact name and number, so, here, we create a new class. Go to Solution Explorer-> Project Name and right click on Add->New Item. Open a new dialog box; select class File and give it a name as ContactList.cs.

Step 5: Next, open Solution Explorer-> Project Name->Resources->Layout->Main.axml. Click to open the Design View and paste the following code.

- <android.support.v7.widget.RecyclerView
- android:id="@+id/recyclerview"
- android:focusable="true"
- android:clickable="true"
- android:clipToPadding="false"
- android:divider="@null"
- android:dividerHeight="0dp"
- android:layout_width="match_parent"
- android:layout_height="match_parent">
- </android.support.v7.widget.RecyclerView>
Step 6
Now, open Solution Explorer-> Project Name->Resources->Layout-> ContactLayout.axml. Click open the Design View and give the following code. Here, we create two textViews, one for Contact Name and another one for Contact Number.

- <TextView
- android:text=""
- android:textAppearance="?android:attr/textAppearanceMedium"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:id="@+id/txtcontactname" />
- <TextView
- android:text=""
- android:textAppearance="?android:attr/textAppearanceSmall"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:id="@+id/txtnumber" />
Step 7: After creating the Design View, open Solution Explorer-> Project Name->MainActivity.cs. Add the following Namespaces.
- using Android.Support.V7.Widget;
- using System.Collections.Generic;
Step 8
Next step is to create variables, then, declare the variables in OnCreate(), and assign ConatctList<> values. But before this, we need to create Recycler adapter. So, add one more class of ContactListAdapter.cs. Go to Solution Explorer-> Project Name. Right click on Add->New Item. A new dialog box opens. Select Class and give it the name ContactListAdapter.cs.

Step 9:Next, open the ContactListAdapter.cs and give the following code:

C# Code
- public class ContactListAdapter < T >
- {
- readonly List < T > mItems;
- RecyclerView.Adapter mAdapter;
- public ContactListAdapter() {
- mItems = new List < T > ();
- }
- public RecyclerView.Adapter Adapter {
- get {
- return mAdapter;
- }
- set {
- mAdapter = value;
- }
- }
- public void Add(T item) {
- mItems.Add(item);
- if (Adapter != null) {
- Adapter.NotifyItemInserted(0);
- }
- }
- public void Remove(int position) {
- mItems.RemoveAt(position);
- if (Adapter != null) {
- Adapter.NotifyItemRemoved(0);
- }
- }
- public T this[int index] {
- get {
- return mItems[index];
- }
- set {
- mItems[index] = value;
- }
- }
- public int Count {
- get {
- return mItems.Count;
- }
- }
- }





Bhabaniprasad JenaPosted Jul 19, 2017, 11:58 AM
Am having huge space between these list of data....what to do.And how to populate it with database tabel....like below string dpPath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "user.db3"); //Call Database var conn = new SQLiteConnection(dpPath); var cmd = new SQLiteCommand(conn); cmd.CommandText = "select coloumn1,coloumn2 from Entity";var r = cmd.ExecuteQuery<Entity>(); Here in r am getting complete table how can i populate it to recycle view.
Vignesh ManiPosted Jul 11, 2016, 5:37 PM
Nice
Anbu ManiPosted Jul 11, 2016, 1:25 AM
Thanks
Anu VPosted Jul 11, 2016, 12:24 AM
Nice share