-
Notifications
You must be signed in to change notification settings - Fork 27
Dropdown Spinner
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):
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()); }
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