public override void OnBindViewHolder(RecyclerView.ViewHolder holder, int position) { if (holder is ScriptsViewHolder vh) { vh.ScriptName.Text = list[position].ScriptName; //check if button has the OnClick listener for set it only once if (!vh.Delete.HasOnClickListeners) { vh.Delete.Click -= BtnDeleteOnClick; vh.Delete.Click += BtnDeleteOnClick; } void BtnDeleteOnClick(object sender, EventArgs e) { vh.ScriptForeground.TranslationX = 0; vh.BtnPlus.SetImageResource(Resource.Drawable.plus_btn); Scripts.ItemTouchHelperAttach(true); DeleteScriptConnection.StartConnectionAsync(MainActivity.Ip, list[position]); list.RemoveAt(position); NotifyDataSetChanged(); NotifyItemChanged(position); NotifyItemRangeChanged(position, list.Count); NotifyItemRemoved(position); } //event unsubscription to don't repeat the subscription if (!vh.BtnPlus.HasOnClickListeners) { vh.BtnPlus.Click -= BtnPlusOnClick; vh.BtnPlus.Click += BtnPlusOnClick; } if (!vh.ScriptName.HasOnClickListeners) { vh.ScriptName.Click -= ScriptOnClick; vh.ScriptName.Click += ScriptOnClick; } //when click on "+" button in script item void BtnPlusOnClick(object sender, EventArgs args) { if (vh.BtnPlusIsClicked == false) { vh.BtnPlusIsClicked = true; ScriptSelectedCounter++; Scripts.SetRunBarVisibility(VisibilityFlags.Visible); //change "+" to check mark vh.BtnPlus.SetImageResource(Resource.Drawable.chech_mark); Scripts.SelectedScripts.Add(list[position]); } else { vh.BtnPlusIsClicked = false; ScriptSelectedCounter--; //change check mark to "+" vh.BtnPlus.SetImageResource(Resource.Drawable.plus_btn); Scripts.SelectedScripts.Remove(list[position]); } if (ScriptSelectedCounter == 0) { Scripts.SetRunBarVisibility(VisibilityFlags.Invisible); } } if (!vh.BtnBack.HasOnClickListeners) { vh.BtnBack.Click -= BtnBackOnClick; vh.BtnBack.Click += BtnBackOnClick; } void BtnBackOnClick(object sender, EventArgs e) { vh.ScriptBackground.Visibility = ViewStates.Gone; vh.ScriptForeground.TranslationX = 0; Scripts.ItemTouchHelperAttach(true); vh.BtnBack.Visibility = ViewStates.Gone; vh.BtnPlus.Visibility = ViewStates.Visible; } } //when click on item void ScriptOnClick(object sender, EventArgs e) { //create the "Script Info" dialog LayoutInflater layoutInflater = LayoutInflater.From(context); View v = layoutInflater.Inflate(Resource.Layout.file_info_dialog, null); Button okayBtn = v.FindViewById <Button>(Resource.Id.ok_btn); TextView dateCreated = v.FindViewById <TextView>(Resource.Id.creating_date); TextView content = v.FindViewById <TextView>(Resource.Id.script_info); dateCreated.Text = list[position].ScriptDateCreated; content.Text = list[position].ScriptData; AlertDialog.Builder builder = new AlertDialog.Builder(context, Resource.Style.AlertDialogTheme); builder.SetView(v); var dialog = builder.Create(); dialog.Show(); dialog.Window.SetBackgroundDrawableResource(Resource.Drawable.script_info_background); //if click on "Okay" — close "Script Info" dialog okayBtn.Click += delegate { dialog.Hide(); }; } }