2017-05-07 66 views
0

我做的,告訴我照片Xamarin項卡上單擊RecyclerView

對於爲例(不包括下面的文字)回收,並且卡視圖:

enter image description here

我對每一張照片的詳細信息,如:位置,名稱等。

現在,我想點擊照片,而不是照片,我會看到我點擊的照片的詳細信息。

這是我的代碼:

class RecyclerViewHolder : RecyclerView.ViewHolder 
{ 
    public ImageView ImageView { get; set; } 

    public RecyclerViewHolder(View itemView) : base(itemView) 
    { 
     ImageView = itemView.FindViewById<ImageView>(Resource.Id.imageView); 
    } 
} 
class RecyclerViewAdapter : RecyclerView.Adapter 
{ 
    private List<PetEntity> _lstData; 


    public RecyclerViewAdapter(List<PetEntity> lstData) 
    { 
     _lstData = lstData; 

    } 

    public override int ItemCount => _lstData.Count; 

    public override void OnBindViewHolder(RecyclerView.ViewHolder holder, int position) 
    { 
     RecyclerViewHolder viewHolder = holder as RecyclerViewHolder; 

     var image = ImageHelper 
      .GetImageBitmapFromUrl(_lstData[position].PictureURL); 

     if (image == null) 
      viewHolder.ImageView.SetImageBitmap(
       ImageHelper.GetImageBitmapFromUrl(
        StaticConst.Uri + "Content/NA.png" 
        )); 
     else 
      viewHolder.ImageView.SetImageBitmap(image); 

    } 

    public override RecyclerView.ViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) 
    { 

     View itemView = LayoutInflater.From(parent.Context). 
      Inflate(Resource.Layout.item, parent, false); 

     RecyclerViewHolder vm = new RecyclerViewHolder(itemView); 
     return vm; 
    } 
} 

我嘗試了一些東西,但沒有成功,所以我沒有添加到我的代碼在這裏。

回答

0

您應該將.Click方法添加到所需的視圖元素。 還必須在OnCreateViewHolder方法來完成:

public override RecyclerView.ViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) 

這將是這樣的:

public override RecyclerView.ViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) 
    { 

     View itemView = LayoutInflater.From(parent.Context). 
      Inflate(Resource.Layout.item, parent, false); 

     RecyclerViewHolder vm = new RecyclerViewHolder(itemView); 
     vm.ImageView.Click += delegate 
    { 

    //Your code here 

    }; 
     return vm; 
    }