need help with click event on an element in a listview, inside getView

carstenrisagercarstenrisager USMember
edited November 2014 in Xamarin.Android

Got a probblem with linearLayout.Click , it is working while the list view only shows enought rows to fill one screen, but onces i add more rows to it, and scroll down past te irst screen, there will be created 2 eventhandler for each row (in my case it will make 2 pop op numberPickers).
And for every "screen" i scroll down, there will be +1 more eventhandler.
The first eventhandler (numberPicker) is always the correct one, while the others are junks i wanna remove.

Here is the code from:
public class ShoppingListAdapter : BaseAdapter, IShoppingListAdapter

public override View GetView(int position, View convertView, ViewGroup parent)
{

        IGroceriesItem curentGroceries = this[position];

        View view = convertView; 

        if (view == null) {
            view = context.LayoutInflater.Inflate(Resource.Layout.ShoppingListRowView, null);
        }


        //updates the groceries on  the listview.
        context.UpdateGroceriesItemView(view, curentGroceries.Name, curentGroceries.Quantity, curentGroceries.UnitType, 
                                        curentGroceries.InCart);

            //Check if there already are an numberpicker to the specifik view in the listview.
    //numberPicker  == list off ints with every position there already are an eventhandler to linearLayout.Click 
        if (!numberPicker.Contains(position))
        {
            numberPicker.Add(position);
            LinearLayout linearLayout = view.FindViewById<LinearLayout>(Resource.Id.Unit);

            // Creating the numberpicker, when clicking the Unit's position
            linearLayout.Click += (object sender, EventArgs e) =>
            {
                NumberPickerDialogFragment dialog = new NumberPickerDialogFragment(context, this, position);
                var ft = context.FragmentManager.BeginTransaction();
                dialog.Show(ft, "Numbers");
            };
        }

        return view;
    }

Posts

Sign In or Register to comment.