我想在點擊回收站項目的回收站視圖中顯示和隱藏一些按鈕。例如,我有一個像這樣的兩個項目的recyclerw視圖recyclerview內的隱藏/顯示按鈕
單擊第一個項目時,應顯示編輯和刪除按鈕。我的適配器代碼是在這裏:
using Android.Support.V7.Widget;
using Android.Views;
using Android.Widget;
using System;
using System.Collections.Generic;
namespace RecyclerViewTest
{
internal class BuyerAdapter : RecyclerView.Adapter
{
public List<Buyer> mlivestock;
public event EventHandler<int> ItemClick;
public BuyerAdapter(List<Buyer> photoAlbum)
{
mlivestock = photoAlbum;
}
public override RecyclerView.ViewHolder
OnCreateViewHolder(ViewGroup parent, int viewType)
{
View itemView = LayoutInflater.From(parent.Context).
Inflate(Resource.Layout.PersonCardView, parent, false);
PhotoViewHolder vh = new PhotoViewHolder(itemView, ItemOnClick);
return vh;
}
void ItemOnClick(int position)
{
if (ItemClick != null)
ItemClick(this, position);
}
public override void
OnBindViewHolder(RecyclerView.ViewHolder holder, int position)
{
PhotoViewHolder vh = holder as PhotoViewHolder;
vh.Agent.Text = mlivestock[position].Agent;
vh.Pen.Text = mlivestock[position].Pen.ToString();
}
public override int ItemCount
{
get { return mlivestock.Count; }
}
}
public class PhotoViewHolder : RecyclerView.ViewHolder
{
public TextView Agent { get; private set; }
public TextView Pen { get; private set; }
public PhotoViewHolder(View itemView, Action<int> listener)
: base(itemView)
{
Agent = itemView.FindViewById<TextView>(Resource.Id.agent);
Pen = itemView.FindViewById<TextView>(Resource.Id.pen);
itemView.Click += (sender, e) => listener(base.AdapterPosition);
}
}
}
我添加了一個「項目單擊」事件應顯示/隱藏的按鈕。我還想要編輯和刪除按鈕的點擊事件。我怎樣才能做到這一點?任何幫助,將不勝感激。
這個答案,而不是嚴格爲您詳細的問題的答案,並告訴你如何處理使用'RecyclerView'時,單擊事件。 https://stackoverflow.com/questions/44520390/disable-all-other-toggle-buttons-in-recycler-view-after-one-is-clicked/44521692#44521692 – Kuffs
其實,重新讀你的問題和答案,它似乎是一個完美契合。 – Kuffs
我想要一個項目點擊事件來顯示並隱藏該項目內的按鈕 – Arti