Spinner ItemSelected event not firing while selecting dropdown item xamarin android

I have added CustomAdapter class to add items for Spinner

Spinner items populated and when i try to select spinner dropdownitem, the ItemSelected event not firing whenever i select any item from the dropdownlist.

spinner.Adapter = new CustomAdapter(this,Android.Resource.Layout.SimpleListItem1 , list);
spinner.LayoutParameters = new ViewGroup.LayoutParams(500, 100);
spinner.ItemSelected += Spinner_ItemSelected;

What could be the cause for this issue

Answers

  • MizanurRahman.0834MizanurRahman.0834 USMember ✭✭
    edited August 2017

    You are not in right track I think. You have to add event in each item of the spinner. So, you have to add the event under the custom adapter like below:

    public override View GetView(int position, View convertView, ViewGroup parent)
    {
    var item = items[position];

            if (convertView == null)
            {
                convertView = context.LayoutInflater.Inflate(Android.Resource.Layout.SimpleSpinnerItem, null);
            }
            var txtView = convertView.FindViewById<TextView>(Android.Resource.Id.Text1);
       txtView.Click += Item_Click;
            return convertView;
        }
    

    private void Item_Click(object sender, EventArgs e)
    {
    //Your cod will be here
    }

    Hope, It will help you.

Sign In or Register to comment.