Exemplo n.º 1
0
        private void CreateItemView(CountryWithFlag item, ComboBoxItemLoadingEventArgs e)
        {
            View originalItemView = e.ItemView;
            var  itemView         = LayoutInflater.FromContext(originalItemView.Context).Inflate(Resource.Layout.custom_item, (ViewGroup)originalItemView.Parent, false);

            TextView  titleView = itemView.FindViewById <TextView>(Resource.Id.textView1);
            ImageView iconView  = itemView.FindViewById <ImageView>(Resource.Id.imageView1);

            titleView.Text = item.Name;
            iconView.SetImageResource(item.ImageId);

            e.ItemView = itemView;
        }
Exemplo n.º 2
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.activity_autocomplete);

            acmSpinner  = (Spinner)FindViewById(Resource.Id.acm_Spinner);
            clearSwitch = (Switch)FindViewById(Resource.Id.clear_switch);

            acmTextView   = (TextView)FindViewById(Resource.Id.acm_textview);
            clearTextView = (TextView)FindViewById(Resource.Id.clear_textview);

            acmTextView.Text   = GetString(Resource.String.AutoCompleteMode);
            clearTextView.Text = GetString(Resource.String.ShowClearButton);

            var toolbar = FindViewById <Toolbar>(Resource.Id.toolbar);

            SetSupportActionBar(toolbar);
            SupportActionBar.Title = GetString(Resource.String.autocomplete);
            SupportActionBar.SetDisplayHomeAsUpEnabled(true);
            SupportActionBar.SetHomeButtonEnabled(true);

            highLightAutoComplete                   = (C1AutoComplete)this.FindViewById(Resource.Id.autocomplete_highlight);
            highLightAutoComplete.ItemsSource       = Country.GetDemoDataList();
            highLightAutoComplete.DisplayMemberPath = "Name";

            customAutoComplete                   = (C1AutoComplete)this.FindViewById(Resource.Id.autocomplete_custom);
            customAutoComplete.ItemsSource       = CountryWithFlag.GetDemoDataList();
            customAutoComplete.DisplayMemberPath = "Name";
            customAutoComplete.ItemLoading      += (object sender, ComboBoxItemLoadingEventArgs e) =>
            {
                CreateItemView(e.Item as CountryWithFlag, e);
            };


            filterAutoComplete = (C1AutoComplete)this.FindViewById(Resource.Id.autocomplete_filter);
            filterAutoComplete.DisplayMemberPath = "Title";
            filterAutoComplete.Filtering        += async(sender, e) =>
            {
                var deferral = e.GetDeferral();
                try
                {
                    var dataCollection = new YouTubeDataCollection();
                    await dataCollection.SearchAsync(e.FilterString);

                    filterAutoComplete.ItemsSource = dataCollection;
                    e.Cancel = true;
                }
                finally
                {
                    deferral.Complete();
                }
            };
            filterAutoComplete.ItemLoading += (object sender, ComboBoxItemLoadingEventArgs e) =>
            {
                CreateYouTubeItemView(e.Item as YouTubeVideo, e);
            };

            ArrayAdapter adapter1 = ArrayAdapter.CreateFromResource(this, Resource.Array.acmSpinnerValues, Android.Resource.Layout.SimpleSpinnerItem);

            // Specify the layout to use when the list of choices appears
            adapter1.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem);
            // Apply the adapter to the spinner
            acmSpinner.Adapter = adapter1;
            acmSpinner.SetSelection(1);
            acmSpinner.ItemSelected += AcmSpinner_ItemSelected;

            clearSwitch.Checked        = false;
            clearSwitch.CheckedChange += ClearSwitch_CheckedChange;
        }