Skip to content
This repository has been archived by the owner on Jan 13, 2018. It is now read-only.

Dropdown Spinner

James Montemagno edited this page May 1, 2013 · 1 revision

LegacyBar has a simple way of creating a dropdown spinner where the Title would usually go. This is great for account selection and is very similar to the account selection you would find in let's say Gmail. Here is an example (on Android < 3.0 a spinner pop up will appear):

drop down

Default Spinner with Strings

Implementing a spinner is as easy as calling: LegacyBar.SetDropDown(this, new string[] { "My First Account", "My Second Account", "My Third Account" }, DropDownSelected);

The parameters are: Context: Current activity string[]: items to show (if none are set it will display the title and hide spinner) EventHandler<AdapterView.ItemSelectedEventArgs>: Callback when item is selected

To implement the callback simply use this: private void DropDownSelected(object sender, AdapterView.ItemSelectedEventArgs args) { RunOnUiThread(() => Toast.MakeText(this, "You selected account: " + args.Position, ToastLength.Short).Show()); }

Custom Adapters

There might be instances where you want to create and use your own adapter you can call: public void SetDropDown(BaseAdapter adapter, EventHandler<AdapterView.ItemSelectedEventArgs> eventHandler)

The base adapter should be set with your items and it will appear in a drop down as normal

Clone this wiki locally