Reputation: 330
For having Click listner on a cell in RecyclerView in Xamarin.Android we have a general methode which is :
mAdapter.ItemClick += OnItemClick; // in OnCreate
and
void OnItemClick (object sender, int position)
{
// Display a toast that briefly shows the enumeration of the selected photo:
int photoNum = position + 1;
Toast.MakeText(this, "This is photo number " + photoNum, ToastLength.Short).Show();
}
In ViewHolder we put this code :
itemView.Click += (sender, e) => listener (base.LayoutPosition);
And in RecyclerView.Adapter we have :
public event EventHandler<int> ItemClick;
with :
// Raise an event when the item-click takes place:
void OnClick (int position)
{
if (ItemClick != null)
ItemClick (this, position);
}
Everything works well, BUT IF I want to have more than one type of click on items in ViewHolder, how can I manage this?
For example, I want to define a click on Image which open an activity. And if user click on TextView in the same ViewHolder, it does another action.
Image = itemView.FindViewById<ImageView> (Resource.Id.imageView);
Image.Click += (sender, e) => listener (base.LayoutPosition);
Caption = itemView.FindViewById<TextView> (Resource.Id.textView);
Caption.Click += ???
Upvotes: 1
Views: 363