First, we create a Recycler View with use of List of items. I already explained it my last article. (refer to the below link)
After completing the Recycler View App creation, please follow the below steps to, easily, create a Click Event.
Step 1: Open Solution Explorer-> Project Name->MainActivity.cs. Add the following Namespaces. We ha already created all the adapter classes to pass the single Recycler value only. But now, we need to pass one more recycler value. Please see the following images:

C# Code
- protected override void OnCreate(Bundle bundle)
- {
- base.OnCreate(bundle);
- SetContentView(Resource.Layout.Main);
- recyclerview = FindViewById < RecyclerView > (Resource.Id.recyclerview);
- List < ContactList > contact = new List < ContactList > ();
- contact.Add(new ContactList {
- ContactName = "Anbu", Number = "2564125624"
- });
- contact.Add(new ContactList {
- ContactName = "Arun", Number = "52459878788"
- });
- contact.Add(new ContactList {
- ContactName = "John", Number = "57879877878"
- });
- contact.Add(new ContactList {
- ContactName = "Peter", Number = "56478989798"
- });
- contact.Add(new ContactList {
- ContactName = "Ali", Number = "12345687945"
- });
- ContactListitems = new ContactListAdapter < ContactList > ();
- foreach(var s in contact) {
- ContactListitems.Add(s);
- }
- recyclerview_layoutmanger = new LinearLayoutManager(this, LinearLayoutManager.Vertical, false);
- recyclerview.SetLayoutManager(recyclerview_layoutmanger);
- recyclerview_adapter = new RecyclerAdapter(ContactListitems, recyclerview);
- recyclerview.SetAdapter(recyclerview_adapter);
- }

C# Code
- public class RecyclerAdapter: RecyclerView.Adapter
- {
- private ContactListAdapter < ContactList > Mitems;
- Context context;
- RecyclerView mrecyle;
- public RecyclerAdapter(ContactListAdapter < ContactList > Mitems, RecyclerView recyler) {
- this.Mitems = Mitems;
- NotifyDataSetChanged();
- mrecyle = recyler;
- }
- public class MyView: RecyclerView.ViewHolder {
- public View mainview {
- get;
- set;
- }
- public TextView mtxtcontactname {
- get;
- set;
- }
- public TextView mtxtcontactnumber {
- get;
- set;
- }
- public EventHandler ClickHandler {
- get;
- set;
- }
- public MyView(View view): base(view) {
- mainview = view;
- }
- }
- public override RecyclerView.ViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
- View listitem = LayoutInflater.From(parent.Context).Inflate(Resource.Layout.ContactLayout, parent, false);
- TextView txtcontactname = listitem.FindViewById < TextView > (Resource.Id.txtcontactname);
- TextView txtnumber = listitem.FindViewById < TextView > (Resource.Id.txtnumber);
- MyView view = new MyView(listitem) {
- mtxtcontactname = txtcontactname, mtxtcontactnumber = txtnumber
- };
- return view;
- }
- public override void OnBindViewHolder(RecyclerView.ViewHolder holder, int position) {
- MyView myholder = holder as MyView;
- myholder.mtxtcontactname.Text = Mitems[position].ContactName;
- myholder.mtxtcontactnumber.Text = Mitems[position].Number;
- myholder.mainview.Click += Mainview_Click;
- }
- private void Mainview_Click(object sender, EventArgs e) {
- int position = mrecyle.GetChildAdapterPosition((View) sender);
- //int indexPosition = (Mitems.Count-0) - position;
- Console.WriteLine(Mitems[position].ContactName);
- //D
- }
- public override int ItemCount {
- get {
- return Mitems.Count;
- }
- }
- }

Finally, We have successfully created the Xamarin Android Click Event using Recycler.

James MazivisePosted Aug 27, 2019, 8:02 AM
How can we call onClick event on the main function?
Ashish PancholiPosted Nov 23, 2017, 6:33 AM
How you are getting postion in click event: private void Mainview_Click(object sender, EventArgs e) { int position = mrecyle.GetChildAdapterPosition((View) sender); //int indexPosition = (Mitems.Count-0) - position; Console.WriteLine(Mitems[position].ContactName); //D } can you explain this because m not able to get the position in click event
Abdelfatah BADAOUIPosted Mar 8, 2017, 12:01 PM
Thank you for your tutorial ,How can we change the background of each item the recyclerview
kalu singh raoPosted Jul 11, 2016, 2:33 AM
Nice...