Forum Xamarin Xamarin.Android

Remove Item from Drop Down Adapter

Xammy10Xammy10 Member ✭✭✭
edited September 2018 in Xamarin.Android

I want to remove the first item on my drop down in spinner.
Do you guys have any idea how to do it?

Thanks in advance :)


  • BillyLiuBillyLiu Member, Xamarin Team Xamurai
    edited September 2018


    You need to create a custom adapter, for example:

    public class MySpinnerAdapter<T> : ArrayAdapter<T>
        private Context mContext;
        private int mTextResourceId;
        public MySpinnerAdapter(Context context, int textViewResourceId) : base(context, textViewResourceId)
            mContext = Context;
            mTextResourceId = textViewResourceId;
        public override View GetView(int position, View convertView, ViewGroup parent)
            View view = base.GetView(position, convertView, parent);
            if (position == Count)
                TextView a = (view.FindViewById<TextView>(Android.Resource.Id.Text1));
                a.Text = "";
                a.Hint = GetItem(Count).ToString();                
            return view;
        public override int Count => (base.Count - 1);

    You could use it by:

            Spinner spinner = FindViewById<Spinner>(Resource.Id.spinner1);
            var adapter = new MySpinnerAdapter<string>(this, Android.Resource.Layout.SimpleSpinnerDropDownItem);
            adapter.Add("Select a value");
            spinner.Adapter = adapter;

    And the result:

Sign In or Register to comment.