public SmartViewHolder(View itemView, IOnItemClickListener mListener) : base(itemView) { this.mListener = mListener; itemView.Click += (sender, e) => { if (mListener != null) { int position = AdapterPosition; if (position >= 0) { mListener.OnItemClick(null, itemView, position, ItemId); } } }; // 设置水波纹背景 if (itemView.Background == null) { TypedValue typedValue = new TypedValue(); if (itemView.Context.Theme.ResolveAttribute(Android.Resource.Attribute.SelectableItemBackground, typedValue, true)) { itemView.SetBackgroundResource(typedValue.ResourceId); } itemView.SetPadding(itemView.PaddingLeft, itemView.PaddingTop, itemView.PaddingRight, itemView.PaddingBottom); } }
public override RecyclerView.ViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) { var view = CreateSpViewByType(parent, viewType); if (view != null) { return(new StateViewHolder(view)); } var viewHolder = onCreateViewHolder(parent, viewType); //itemView 的点击事件 if (mItemClickListener != null) { viewHolder.ItemView.Click += (sender, e) => { mItemClickListener.OnItemClick(viewHolder.AdapterPosition - headers.Count); }; } if (mItemLongClickListener != null) { viewHolder.ItemView.LongClick += (sender, e) => { e.Handled = mItemLongClickListener.OnItemLongClick(viewHolder.AdapterPosition - headers.Count); }; } return(viewHolder); }
public void OnItemClick(AdapterView parent, View view, int position, long id) { if (mItemClickListener != null) { mItemClickListener.OnItemClick(parent, view, position - HeaderViewsCount, id); //手动减headerview } }
private Boolean performPinnedItemClick() { if (mPinnedSection == null) { return(false); } IOnItemClickListener listener = OnItemClickListener; if (listener != null) { View view = mPinnedSection.view; PlaySoundEffect(SoundEffects.Click); if (view != null) { view.SendAccessibilityEvent(Android.Views.Accessibility.EventTypes.ViewClicked); } listener.OnItemClick(this, view, mPinnedSection.position, mPinnedSection.id); return(true); } return(false); }
private bool PerformPinnedItemClick() { if (mPinnedSection == null) { return(false); } IOnItemClickListener listener = OnItemClickListener; if (listener != null && Adapter.IsEnabled(mPinnedSection.Position)) { View view = mPinnedSection.ViewHolder; PlaySoundEffect(SoundEffects.Click); if (view != null) { view.SendAccessibilityEvent(Android.Views.Accessibility.EventTypes.ViewClicked); } listener.OnItemClick(this, view, mPinnedSection.Position, mPinnedSection.ID); return(true); } return(false); }