title: Can't set up Listener in RecyclerView.Adapter, Casting issue
body: <p>I've been trying to get this code running since the morning. I have a DialogFragment, which holds a Recycle View and it's the adapter. When I touch an item in the adapter it changes colour and sets that item with a flag. I want a listener to connect the touches to the Dialog so I'm able to pull the data. I have the below code...</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using Android;
  using Android.Support.V7.Widget;
  using Android.Views;
  using System.Linq;
  using RecordMilk.ViewHolders;
  using RecordMilk.Classes;
  using Newtonsoft.Json;
  using RecordMilk.Dialogs;
  
  public class PregnantAnimalAdapter : RecyclerView.Adapter
  {
  public PregnantAnimalAdapter pregnantAnimalAdapter;
  public List&lt;Animal&gt; mAnimals;
  public Herd passedHerd;
  public OnFinishClick callback;
  public OnItemClick itemCallback;
  string[] animalTags;
  //public event EventHandler&lt;int&gt; ItemClick;
  
  public interface OnFinishClick
  {
      void OnFinishClick(List&lt;Animal&gt; animals);
  }
  
  public interface OnItemClick
  {
      void OnItemClick(List&lt;Animal&gt; animals);
  }
  
  public PregnantAnimalAdapter(string SerializedString)
  {
      passedHerd = JsonConvert.DeserializeObject&lt;Herd&gt;(SerializedString);
  
      List&lt;Animal&gt; animals = passedHerd.Animals.ToList();
      animalTags = animals.Select(x =&gt; x.FreezeBrand).ToArray();
  
      var size = from x in animalTags
                 orderby x.Length, x
                 select x;
  
      animalTags = size.ToArray();
  
      mAnimals = animals;
  }
  
  
  
  public override RecyclerView.ViewHolder OnCreateViewHolder(ViewGroup parent, int viewType)
  {
      View itemView = LayoutInflater.From(parent.Context).
                                    Inflate(global::RecordMilk.Resource.Layout.PregnancyItem, parent, false);
  
      try
      {
          // Getting Casting Error here...
          itemCallback = (OnItemClick)parent.Context;
      }
      catch (Exception e)
      {
          Console.WriteLine(e);
      }
  
      PregnantAnimalViewHolder vh = new PregnantAnimalViewHolder(itemView);
  
      vh.mBackground.Click += (object sender, EventArgs e) =&gt;
      {
          Animal pregAnimal = mAnimals.Find(x =&gt; x.FreezeBrand == animalTags[vh.AdapterPosition]);
  
          pregAnimal.Pregnant = !pregAnimal.Pregnant;
  
          if (pregAnimal.Pregnant)
          {
              vh.mBackground.SetBackgroundResource(RecordMilk.Resource.Color.munster_yellow);
          }
          else
          {
              vh.mBackground.SetBackgroundResource(Resource.Color.White);
          }
          NotifyDataSetChanged();
  
          itemCallback.OnItemClick(mAnimals);
      };
  
      return vh;
  }
  
  public override void OnAttachedToRecyclerView(RecyclerView recyclerView)
  {
      base.OnAttachedToRecyclerView(recyclerView);
  
  }
  
  public override void OnBindViewHolder(RecyclerView.ViewHolder holder, int position)
  {
  
      PregnantAnimalViewHolder vh = holder as PregnantAnimalViewHolder;
  
      vh.mAnimalTag.Text = animalTags[position];
  
      if (mAnimals.Find(x =&gt; x.FreezeBrand == animalTags[position]).Pregnant == true)
      {
          vh.mBackground.SetBackgroundResource(RecordMilk.Resource.Color.munster_yellow);
      }
      else
      {
          vh.mBackground.SetBackgroundResource(Resource.Color.White);
      }
  }
  
  public override int ItemCount
  {
      get { return mAnimals.Count; }
  }
  }
  </code></pre>
  
  <p>The error I'm getting is:</p>
  
  <blockquote>
    <p>System.InvalidCastException: Specified cast is not valid.
      at PregnantAnimalAdapter.OnCreateViewHolder (Android.Views.ViewGroup parent, System.Int32 viewType)</p>
  </blockquote>
  
  <p>I had this code in an Activity previously and worked as expected. But I needed to put the functionality into a DialogFragment which is where the issue started showing itself.</p>