Selection alerts
Sometimes we have to ask the user to select one or more items from a larger collection. This may be necessary as normal dialogs only have up to three buttons, but a fully customized UI is unnecessary.
How to do it...
To provide a list of items in a dialog, we can specify the items in much the same way as a simple message:
If we need to provide the user with a selection of items in a dialog, we can also use the
AlertDialog
instance and theSetItems()
method:string[] items = new string[] { ... } using (var dialog = new AlertDialog.Builder(this)) { dialog.SetTitle("Alert Title"); dialog.SetPositiveButton("Close", delegate { }); dialog.SetItems(items, (s, e) => { int index = e.Which; }); dialog.Show(); }
We can also use data adapters in a dialog, through the
SetAdapter()
method:var adapter = new ArrayAdapter( this, Android.Resource.Layout.SimpleListItem1, items); dialog.SetAdapter(adapter, (s, e) => { var index = e.Which; });
If we want to support a single...