-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPhotoAdapter.cs
58 lines (46 loc) · 1.69 KB
/
PhotoAdapter.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using Android.Support.V7.Widget;
using Android.Views;
using Android.Widget;
using System;
namespace HellowWorldNativeClassic
{
public class PhotoAdapter : RecyclerView.Adapter
{
// Event handler for item clicks:
public event EventHandler<int> ItemClick;
Photo[] mPhts;
public PhotoAdapter(Photo[] photos)
{
mPhts = photos;
}
public override int ItemCount => mPhts.Length;
public override void OnBindViewHolder(RecyclerView.ViewHolder holder, int position)
{
Photo photoData = mPhts[position];
var holderView = holder as MyViewHolder;
holderView.photo.SetImageResource(photoData.PhotoID);
holderView.namePht.Text = photoData.Caption;
}
public override RecyclerView.ViewHolder OnCreateViewHolder(ViewGroup parent, int viewType)
{
View v = LayoutInflater.From(parent.Context).Inflate(Resource.Layout.item_layout_photos, parent,false);
return new MyViewHolder(v,OnClick);
}
public class MyViewHolder : RecyclerView.ViewHolder
{
public ImageView photo { get; set; }
public TextView namePht { get; set; }
public MyViewHolder(View view, Action<int> action) : base(view)
{
photo = view.FindViewById<ImageView>(Resource.Id.imageView);
namePht = view.FindViewById<TextView>(Resource.Id.textView);
view.Click += (sender, e) => action(base.LayoutPosition);
}
}
void OnClick(int position)
{
if (ItemClick != null)
ItemClick(this, position);
}
}
}