Hello,
I had a similar issue and fixed it by using the ViewHolder-pattern. You seem to already be using it so I would like to show you how I would initialize it.
public override View GetView(int position, View convertView, ViewGroup parent)
{
ProductViewHolder holder = null;
RetrieveState();
if (convertView == null)
holder = view.Tag as ProductViewHolder;
if (holder == null)
{
holder = new ProductViewHolder();
convertView = context.LayoutInflater.Inflate(
Resource.Layout.ProductListTabView,parent,false);
...
holder.Tag = holder;
}
}
This way the holder is not re-initialized multiple times even if
convertView
were to change to
null
at a later time. The holder works kind of like a Singleton if you are familiar with that pattern, since it is guaranteed to only be created once. And therefore the statement
holder.ivPlus.Click += delegate {... }
will only get called once.
In C# you add a function pointer (delegate) to an event handler by using the += operator. In your case, you add a new function pointer to the handler to call every time
convertView
is
null
, leading to it seeming like multiple click events were fired.
There is no way to assign only one function pointer to an event handler, it works like a list to which you can either add with
+=
or remove with
-=
.