void ShowSelectionDialog(string caption, KeyValuePair <object, string>[] items, int index, DialogButton <object> positive, DialogButton <object> negative) { using (var builder = new AlertDialog.Builder(_activity)) { builder.SetTitle(caption); var rows = new string[items.Length]; for (int i = 0; i < items.Length; i++) { rows[i] = items[i].Value; } var adapt = new ArrayAdapter <string>(_activity, Android.Resource.Layout.SelectDialogSingleChoice, rows); builder.SetSingleChoiceItems(adapt, index, (e, args) => { }); builder.SetPositiveButton(positive.Caption, (sender, e) => { int pos = ((AlertDialog)sender).ListView.CheckedItemPosition; if (pos < items.Length) { object result = items[pos].Key; positive.Execute(result); } }); builder.SetNegativeButton(negative.Caption, (sender, e) => negative.Execute()); builder.SetCancelable(false); AlertDialog dialog = builder.Show(); dialog.DismissEvent += DisposeDialog; Dialogs.Push(dialog); } }
public async Task <int?> ShowItemsPicker(IEnumerable <string> items, int selectedIndex, string title, string cancelText, string okText) { var semaphore = new SemaphoreSlim(0); var builder = new AlertDialog.Builder(_contextProvider.CurrentContext); int?selectedItem = selectedIndex; builder.SetTitle(title); builder.SetSingleChoiceItems(items.ToArray(), selectedIndex, (sender, args) => { selectedItem = args.Which; }); builder.SetNegativeButton(cancelText, (sender, args) => { selectedItem = null; semaphore.Release(); }); builder.SetPositiveButton(okText, (sender, args) => semaphore.Release()); var dialog = builder.Create(); dialog.SetCanceledOnTouchOutside(false); dialog.SetCancelable(false); dialog.Show(); await semaphore.WaitAsync(); dialog.Dismiss(); return(selectedItem); }
public void Filter(string[] categories, int selected, Func <int, int> callback) { AlertDialog ad = null; var currentSelection = selected - 1; var top = Mvx.Resolve <IMvxAndroidCurrentTopActivity>(); var act = top.Activity; var adb = new AlertDialog.Builder(act, _alertDialogThemeId); adb.SetCancelable(true); adb.SetTitle(Resource.String.activity_filter_title); if (categories.Length == 0) { adb.SetMessage(Resource.String.activity_filter_empty); } else { adb.SetSingleChoiceItems(categories, currentSelection, (sender, args) => { callback(args.Which + 1); ad?.Dismiss(); }); //adb.SetPositiveButton("Выбрать", // (sender, args) => callback(currentSelection)); } adb.SetNegativeButton("Назад", (sender, args) => { }); ad = adb.Show(); }
protected override Dialog OnCreateDialog(int id) { ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences(this); ISharedPreferencesEditor editor = prefs.Edit(); var builder = new AlertDialog.Builder(this); builder.SetTitle("Set Value"); builder.SetSingleChoiceItems(new string [] { "Integer", "Decimal" }, 0, (o, e) => { if (e.Which == 0) { SaleFormat = "Integer"; } else if (e.Which == 1) { SaleFormat = "Decimal"; } editor.PutBoolean("default_settings", false); }); builder.SetNegativeButton("Cancel", (s, a) => { DismissDialog(1); }); builder.SetPositiveButton("Confirm", (s, a) => { editor.PutString("sales_format", SaleFormat); editor.Apply(); InitializeConfigs(prefs); }); return(builder.Create()); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); using (var db = new SQLiteConnection(dbPath)) { db.CreateTable <LogEntry> (); } // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); // Create our database if it does not already exist // Get our button from the layout resource, // and attach an event to it Button addFood = FindViewById <Button> (Resource.Id.AddFoodButton); addFood.Click += (object sender, EventArgs e) => { AlertDialog.Builder addFoodDialogBuilder = new AlertDialog.Builder(this); addFoodDialogBuilder.SetTitle("I had something to eat and it was:"); addFoodDialogBuilder.SetSingleChoiceItems(choices, -1, clickFoodDialogList); addFoodDialog = addFoodDialogBuilder.Create(); // Show the alert dialog to the user and wait for response. addFoodDialog.Show(); }; }
//This is deprecated in API level 8 //protected override Dialog OnCreateDialog(int id) //This is deprecated in API level 13 protected override Dialog OnCreateDialog(int id, Bundle args) { switch (id) { case AlertDialog: { var builder = new AlertDialog.Builder(this); builder.SetIconAttribute(Android.Resource.Attribute.AlertDialogIcon); builder.SetTitle(Resource.String.bomb_dialog_title); builder.SetPositiveButton(Resource.String.dialog_signal, (s, e) => { /*Do something here!*/ }); builder.SetNegativeButton(Resource.String.dialog_main_screen, (s, e) => { }); return(builder.Create()); } case ListDialog: { var builder = new AlertDialog.Builder(this); builder.SetIconAttribute(Android.Resource.Attribute.AlertDialogIcon); builder.SetTitle(Resource.String.list_dialog_title); builder.SetSingleChoiceItems(Resource.Array.list_dialog_items, 0, ListClicked); builder.SetPositiveButton(Resource.String.dialog_ok, OkClicked); builder.SetNegativeButton(Resource.String.dialog_cancel, CancelClicked); return(builder.Create()); } case MultiChoiceDialog: { var builder = new AlertDialog.Builder(this, Android.App.AlertDialog.ThemeHoloLight); builder.SetIcon(Resource.Drawable.Icon); builder.SetTitle(Resource.String.multi_choice_dialog_title); builder.SetMultiChoiceItems(Resource.Array.multilist_dialog_items, new[] { false, true, false, true }, MultiListClicked); builder.SetPositiveButton(Resource.String.dialog_ok, OkClicked); builder.SetNegativeButton(Resource.String.multi_dialog_cancel, CancelClicked); return(builder.Create()); } case CustomViewDialog: { var customView = LayoutInflater.Inflate(Resource.Layout.CustomDialog, null); var builder = new AlertDialog.Builder(this); builder.SetView(customView); builder.SetPositiveButton(Resource.String.dialog_ok, OkClicked); builder.SetNegativeButton(Resource.String.dialog_cancel, CancelClicked); return(builder.Create()); } } return(base.OnCreateDialog(id, args)); }
public void SelectRadio() { var dialog = new AlertDialog.Builder(Context); dialog.SetSingleChoiceItems(Sections.SelectMany(s => s).OfType <RadioElement>().Select(e => e.Summary()).ToArray(), RadioSelected, this); dialog.SetTitle(Caption); dialog.SetNegativeButton("Cancel", this); dialog.Create().Show(); }
public void Sort(List <WorkshopPreview> list) { AlertDialog.Builder builder = new AlertDialog.Builder(ctx); builder.SetTitle("Sort By"); builder.SetSingleChoiceItems(items.Select(x => x.title).ToArray(), selected, new MultiClickListener(this)); var clickListener = new ActionClickListener(listAdapter, listView, list, this, true, isWorkshop); builder.SetPositiveButton("Sort", clickListener); builder.SetNegativeButton("Cancel", clickListener); builder.Create().Show(); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); // Create your application here SetContentView(Resource.Layout.Home); FindViewById<Button>(Resource.Id.btnNovo).Click += (sender, e) => { var user = Serializador.LoadFromXMLString<Usuario>(PreferenceManager.GetDefaultSharedPreferences(this).GetString("user", "")); var display = user.Lojas.Select<Loja, String>(loja => loja.ERP.Codigo + " - " + loja.ERP.Nome).ToList(); var lojasAdapter = new ArrayAdapter<String>(this, Android.Resource.Layout.SimpleListItemSingleChoice, display); int shopIndex = 0; AlertDialog.Builder alerta = new AlertDialog.Builder(this); alerta.SetTitle("Informe a empresa"); alerta.SetSingleChoiceItems(lojasAdapter, shopIndex,(s, v) => { shopIndex = v.Which; }); alerta.SetPositiveButton("Cancelar", (s, v) => { }); alerta.SetNegativeButton("Confirmar", (s, v) => { PreferenceManager.GetDefaultSharedPreferences(this).Edit().PutString("shop", Serializador.ToXML(user.Lojas[shopIndex])).Apply(); StartActivity(new Intent(this, typeof(OrderActivity))); }); alerta.Show(); }; FindViewById<Button>(Resource.Id.btnSalvos).Click += (sender, e) => { StartActivity(new Intent(this, typeof(ExportListActivity))); }; FindViewById<Button>(Resource.Id.btnSair).Click += (sender, e) => { AlertDialog.Builder alert = new AlertDialog.Builder(this); alert.SetTitle("Sair"); alert.SetMessage("Deseja efetuar o logout?"); alert.SetPositiveButton("Sim", (s, v) => { StartActivity(new Intent(this, typeof(LogoutActivity))); }); alert.SetNegativeButton("Não", (s, v) => { }); alert.Create().Show(); }; FindViewById<TextView>(Resource.Id.lblVendedor).Text = PreferenceManager.GetDefaultSharedPreferences(this).GetString("employeeName", ""); FindViewById<TextView>(Resource.Id.lblVersao).Text = "versão 1.2"; if (Request.GetInstance().Uri.Equals(Database.Teste)) FindViewById<TextView>(Resource.Id.lblVersao).Text += " BASE TESTE"; }
public static async Task <object> ShowSingleChoiseDlg(Context context, string title, object[] items, string textProperty, bool bAllowAbort = true) { tcsScDlg = new TaskCompletionSource <int>(); List <string> textS = new List <string>(); foreach (object x in items) { try { if (x == null) { textS.Add("_empty_"); } else { x.GetType().GetProperty(textProperty).GetValue(x).ToString(); } } catch { textS.Add(string.Concat("_error_", x)); } } MainThread.BeginInvokeOnMainThread(() => { var builder = new AlertDialog.Builder(context).SetTitle(title); if (bAllowAbort) { builder = builder.SetNegativeButton(context.Resources.GetString(Resource.String.action_yes), (s, e) => { tcsYnMsg.TrySetResult(false); }); } builder = builder.SetSingleChoiceItems(textS.ToArray(), -1, new SingleChoiceClickListener(tcsScDlg)); builder = builder.SetOnCancelListener(new myDialogCancelListener <int>(tcsScDlg)); var dlg = builder.Create(); dlg.Show(); }); await tskScDlg; int iRes = tskScDlg.Result; if (iRes < 0) { return(null); } else { return(items[iRes]); } }
private void InitializeReviewAlertDialog() { string[] reviewOptions = new[] { Resources.GetString(Resource.String.DuringCredits), Resources.GetString(Resource.String.AfterCredits), Resources.GetString(Resource.String.DuringAfterCredits) }; _reviewBuilderAlertDialog = new AlertDialog.Builder(Activity); _reviewBuilderAlertDialog.SetTitle(Resources.GetString(Resource.String.When)); _reviewBuilderAlertDialog.SetSingleChoiceItems(reviewOptions, 0, OnAlertDialogItem_Click); _reviewBuilderAlertDialog.SetNeutralButton(Resources.GetString(Resource.String.Confirm), OnAlertDialogOkButton_Click); _reviewDialog = _reviewBuilderAlertDialog.Create(); }
protected override void OnPrepareDialogBuilder(AlertDialog.Builder builder) { EventHandler <DialogClickEventArgs> onClick = (o, e) => { var dialog = (AlertDialog)o; SetValueIndex((int)e.Which); OnClick((AlertDialog)o, DialogInterfaceButton.Positive); dialog.Dismiss(); }; var adapter = CreateAdapter(); builder.SetSingleChoiceItems(adapter, FindIndexOfValue(Value), onClick); HideOkButton(builder); }
private string GetOptionFromListDialog(int resTitle, int resLabel, int resValue, string selectedValue) { string[] labels = Resources.GetStringArray(resLabel); string[] values = Resources.GetStringArray(resValue); dialogReturnStringValue = selectedValue; dialogHandler = new Handler(m => { throw new Java.Lang.RuntimeException(); }); dialogBuilder = new AlertDialog.Builder(this); dialogBuilder.SetTitle(Resources.GetString(resTitle)); int checkedItem = Array.IndexOf(values, selectedValue); dialogBuilder.SetSingleChoiceItems(resLabel, checkedItem, (c, ev) => { dialogReturnStringValue = values[ev.Which]; }); dialogBuilder.SetPositiveButton(Resource.String.ok, (c, ev) => { dialogHandler.SendMessage(dialogHandler.ObtainMessage()); }); dialogBuilder.SetNegativeButton(Resource.String.cancel, (cw, ev) => { dialogReturnStringValue = selectedValue; dialogHandler.SendMessage(dialogHandler.ObtainMessage()); }); settingDialog = dialogBuilder.Create(); settingDialog.Show(); try { Looper.Loop(); } catch (Java.Lang.RuntimeException) { } return(dialogReturnStringValue); }
public void ShowActionSheet(string title, string subTitle, string[] list, Action <int> callBack) { var dlg = new AlertDialog.Builder(Forms.Context); dlg.SetTitle(title); dlg.SetSingleChoiceItems(list, -1, (s, a) => { var index = list.IndexOf(list[a.Which]); callBack?.Invoke(index); ((AlertDialog)s).Dismiss(); }); dlg.SetPositiveButton("Cancel", (s, a) => { }); var dialog = dlg.Show(); }
protected override void OnCreate(Android.OS.Bundle savedInstanceState) { base.OnCreate(savedInstanceState); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.SetTitle(Resource.String.export_fileformats_title); builder.SetSingleChoiceItems(Resource.Array.export_fileformat_options, _fileFormatIndex, delegate(object sender, DialogClickEventArgs args) { _fileFormatIndex = args.Which; }); builder.SetPositiveButton(Android.Resource.String.Ok, delegate { _exportDbProcessManager = new ExportDbProcessManager(0, this, _ffp[_fileFormatIndex]); _exportDbProcessManager.StartProcess(); }); builder.SetNegativeButton(Resource.String.cancel, delegate { Finish(); }); builder.Show(); }
private void OpenPlanPopUp(string email) { string[] arrplans = null; try { GeneralValues objGeneralValues = new GeneralValues(); planfetchdialog = ProgressDialog.Show(this, "Fectching Plan", "Please wait....."); StreamReader reader = null; var webrequest = (HttpWebRequest)WebRequest.Create("https://api.stripe.com/v1/plans?limit=3"); webrequest.Method = "GET"; webrequest.Headers.Add("Authorization", "Bearer " + objGeneralValues.SecretKey); HttpWebResponse webresponse = (HttpWebResponse)webrequest.GetResponse(); reader = new StreamReader(webresponse.GetResponseStream()); string obj = reader.ReadToEnd(); var parsedjson = JObject.Parse(obj)["data"].Value <JArray>(); string[] arrlist = new string[parsedjson.Count]; arrplans = new string[parsedjson.Count]; int i = 0; foreach (var item in parsedjson) { var parseditemjson = JObject.Parse(item.ToString().Replace("{{", "{").Replace("}}", "}")); string planname = parseditemjson["name"].ToString(); string amount = parseditemjson["amount"].ToString(); string currency = parseditemjson["currency"].ToString(); string id = parseditemjson["id"].ToString(); arrlist[i] = planname; arrplans[i] = planname + "|||" + amount + "|||" + id; i = i + 1; } planfetchdialog.Dismiss(); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.SetTitle("Choose plan"); builder.SetSingleChoiceItems(arrlist, 0, ListClicked); builder.SetNeutralButton("Ok", (object sender, DialogClickEventArgs e) => { string item = arrplans[selecteditempositin].ToString(); var token = CreateToken(item, email); }); builder.SetCancelable(false); builder.Show(); } catch (Exception ex) { } }
private void changePrice() { var display = item.Produto.Precos.Select <Preco, String>(preco => preco.ToString(CultureInfo.GetCultureInfo("pt-BR"))).ToList(); var adapter = new ArrayAdapter <String>(this, Android.Resource.Layout.SimpleListItemSingleChoice, display); int index = 0; AlertDialog.Builder alerta = new AlertDialog.Builder(this); alerta.SetTitle("Tabela de preços"); alerta.SetSingleChoiceItems(adapter, index, (sender, e) => { index = e.Which; }); alerta.SetPositiveButton("Confirmar", (sender, e) => { item.IdPreco = item.Produto.Precos.ElementAt(index).Id; UpdateScreen(); }); alerta.Show(); }
public override Dialog OnCreateDialog(Bundle savedInstanceState) { var builder = new AlertDialog.Builder(Context); if (ViewModel.IsSingleChoice) { var selectedItem = ViewModel.Options.FirstOrDefault(item => item.IsSelected); builder.SetSingleChoiceItems(ViewModel.Options.Select(o => o.ToString()).ToArray(), ViewModel.Options.IndexOf(selectedItem), ItemSelected); } else { builder.SetMultiChoiceItems(ViewModel.Options.Select(o => o.ToString()).ToArray(), ViewModel.Options.Select(o => o.IsSelected).ToArray(), (EventHandler <DialogMultiChoiceClickEventArgs>)null); } return(builder.Create()); }
private void ShowOrderDialog() { var dialog = new AlertDialog.Builder(Activity); dialog.SetTitle(GetString(Resource.String.edic_orderBy)); String[] items = { " " + GetString(Resource.String.pub_title) + " ", " " + GetString(Resource.String.pub_date) + " ", " " + GetString(Resource.String.pub_author) + " ", " " + GetString(Resource.String.pub_expire) + " " }; dialog.SetSingleChoiceItems(items, DataManager.Get <IPreferencesManager>().Preferences.EdicolaOrder, OrderChoiceClicked); dialog.Create(); dialog.Show().SetDivider(); }
protected override void OnCreate(Android.OS.Bundle savedInstanceState) { base.OnCreate(savedInstanceState); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.SetTitle(Resource.String.export_fileformats_title); builder.SetSingleChoiceItems(Resource.Array.export_fileformat_options, _fileFormatIndex, delegate(object sender, DialogClickEventArgs args) { _fileFormatIndex = args.Which; }); builder.SetPositiveButton(Android.Resource.String.Ok, delegate { Intent intent = new Intent(this, typeof(FileStorageSelectionActivity)); //intent.PutExtra(FileStorageSelectionActivity.AllowThirdPartyAppSend, true); StartActivityForResult(intent, 0); }); builder.SetNegativeButton(Resource.String.cancel, delegate { Finish(); }); builder.Show(); }
private AlertDialog ShowChoices(String title, String actionButtonTitle, String cancelButtonTitle, string[] choices, int initialSelectedIndex, ShowChoicesDelegate showChoicesDelegate, VoidDelegate cancelDelegate) { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.SetTitle(title); int choice = initialSelectedIndex; builder.SetSingleChoiceItems(choices, initialSelectedIndex, (senderAlert, args) => { choice = args.Which; }); if (actionButtonTitle == "") { actionButtonTitle = "ok"; } builder.SetPositiveButton(actionButtonTitle, (senderAlert, args) => { showChoicesDelegate(choice, choices[choice]); }); if (cancelButtonTitle != null) { if (cancelButtonTitle == "") { cancelButtonTitle = "cancel"; } builder.SetNegativeButton(cancelButtonTitle, (senderAlert, args) => { if (cancelDelegate != null) { cancelDelegate(); } }); } else { builder.SetCancelable(false); } return(builder.Show()); }
public void SelectRadio() { var radio = _group as RadioGroup; if (radio == null) { return; } var dialog = new AlertDialog.Builder(Context); dialog.SetSingleChoiceItems( Sections.SelectMany(s => s) .Where(e => e is IRadioElement) .Select(e => e.Summary()).ToArray(), RadioSelected, this); dialog.SetTitle(Caption); dialog.SetNegativeButton("Cancel", this); dialog.Create().Show(); }
public static async Task <int> ShowSingleChoiseDlg(Context context, string title, IListAdapter items, bool bAllowAbort = true) { tcsScDlg = new TaskCompletionSource <int>(); MainThread.BeginInvokeOnMainThread(() => { var builder = new AlertDialog.Builder(context).SetTitle(title); if (bAllowAbort) { builder = builder.SetNegativeButton(context.Resources.GetString(Resource.String.action_abort), (s, e) => { tcsYnMsg.TrySetResult(false); }); } builder = builder.SetSingleChoiceItems(items, -1, new SingleChoiceClickListener(tcsScDlg)); builder = builder.SetOnCancelListener(new myDialogCancelListener <int>(tcsScDlg)); var dlg = builder.Create(); dlg.Show(); }); await tskScDlg; return(tskScDlg.Result); }
public static void ShowSingleSelectListString(Context context, string[] items, Action <string> actionOnSelect, string selectedItemName = null, string dialogTitle = null) { var checkedItem = -1; if (selectedItemName != null) { checkedItem = items.ToList().IndexOf(selectedItemName); } var alertDialog = default(AlertDialog); AlertDialog.Builder buider = new AlertDialog.Builder(context); var title = dialogTitle != null ? dialogTitle : "Wybierz element"; buider.SetTitle(title); buider.SetSingleChoiceItems(items, checkedItem, (sender, args) => { actionOnSelect(items[args.Which]); alertDialog.Dismiss(); }); alertDialog = buider.Create(); alertDialog.Show(); }
public void SelectRadio() { List <string> items = new List <string>(); foreach (var s in Sections) { foreach (var e in s.Elements) { if (e is RadioElement) { items.Add(e.Summary()); } } } var dialog = new AlertDialog.Builder(Context); dialog.SetSingleChoiceItems(items.ToArray(), this.RadioSelected, this); dialog.SetTitle(this.Caption); dialog.SetNegativeButton("Cancel", this); dialog.Create().Show(); }
public void Choose(Context context) { AlertDialog.Builder builder = new AlertDialog.Builder(context) .SetTitle("Select Theme") .SetPositiveButton(Android.Resource.String.Ok, delegate { Toast .MakeText(context, themes[selected], ToastLength.Short) .Show(); var tmpTheme = (Theme)Activator.CreateInstance(Theme.ChartThemes[selected]); tmpTheme.Apply(chart); }) .SetNegativeButton(Android.Resource.String.Cancel, CancelClicked); builder.SetSingleChoiceItems(themes, selected, (sender, args) => { selected = args.Which; }); builder.Create().Show(); }
public async Task <string> alertListString(string title, string[] list, string confirm, string cancel) { notes = list; Application.SynchronizationContext.Post(_ => { var mvxTopActivity = Mvx.Resolve <IMvxAndroidCurrentTopActivity>(); AlertDialog.Builder alertDialog = new AlertDialog.Builder(mvxTopActivity.Activity); alertDialog.SetTitle(title); alertDialog.SetSingleChoiceItems(list, -1, listener); dialog = alertDialog.Create(); dialog.DismissEvent += (object sender, EventArgs e) => { button = true; dialog.Dismiss(); }; dialog.Show(); }, null); while (!button) { await Task.Delay(300); } return(text); }
public void getdiag(AppPreferences hh) { // setup the alert builder AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.SetTitle("اختر نوع المتصفح الذي تفضله:"); // add a radio button list String[] animals = { "المتصفح الداخلي الذي يأتي مع الاندرويد...", "المتصفح كروسوك المستقل يحتاج للتثبيت مرة واحدة فقط..." }; int checkedItem = 0; // cow builder.SetSingleChoiceItems(animals, checkedItem, (s, e) => { checkedItem = e.Which; Log.Debug("hhhhhhhh", e.Which.ToString()); }); builder.SetPositiveButton("ok", (s, e) => { if (checkedItem == 0) { Toast.MakeText(this, "notCross ", ToastLength.Short).Show(); hh.saveAccessKey("notCross", "PREFERENCE_WEBVIEW_TYPE"); StartActivity(new Intent(Application.Context, typeof(WvActivity)).AddFlags(ActivityFlags.NoAnimation)); } else { Toast.MakeText(this, "Cross ", ToastLength.Short).Show(); hh.saveAccessKey("Cross", "PREFERENCE_WEBVIEW_TYPE"); StartActivity(new Intent(Application.Context, typeof(CrossActivity)).AddFlags(ActivityFlags.NoAnimation)); } }); AlertDialog dialog = builder.Create(); dialog.Show(); dialog.SetCanceledOnTouchOutside(false); }
/// <summary> /// 单选对话框 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Btn2_Click(object sender, EventArgs e) { AlertDialog.Builder ad_build = new AlertDialog.Builder(this); string[] array = new string[] { "语文", "数学", "英语" }; int selectIndex = 0; //默认是第一项 ad_build.SetSingleChoiceItems(array, 0, new EventHandler <DialogClickEventArgs>((object o2, DialogClickEventArgs e2) => { selectIndex = e2.Which; //可捕获用户选中的值 MessageBoxShow("你选择的是" + array[e2.Which]); })); ad_build.SetNegativeButton("确定", new System.EventHandler <DialogClickEventArgs>((object o2, DialogClickEventArgs e2) => { //直接获取,e2.Which会出现-2,所以利用上面的结果来赋值 //MessageBoxShow("你选择的是" + array[e2.Which]); MessageBoxShow("你最终选择的是:" + array[selectIndex]); })); ad_build.SetPositiveButton("取消", new System.EventHandler <DialogClickEventArgs>((object o3, DialogClickEventArgs e3) => { MessageBoxShow("已取消"); })); ad_build.SetIcon(Android.Resource.Drawable.StatSysWarning); ad_build.Show(); }
///////////////////////////////////////////////////////////////////////////////////////////////////////// ////// START DIALOG DEFINITION ////// ////////////////////////////////////////////////////////////////////////////////////////////////////////// private AlertDialog.Builder CreateDirectoryChooserDialog(String title, List <String> listItems, EventHandler <DialogClickEventArgs> onClickListener) { AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(_mContext); //////////////////////////////////////////////// // Create title text showing file select type // //////////////////////////////////////////////// _mTitleView1 = new TextView(_mContext); _mTitleView1.LayoutParameters = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent); //m_titleView1.setTextAppearance(m_context, android.R.style.TextAppearance_Large); //m_titleView1.setTextColor( m_context.getResources().getColor(android.R.color.black) ); if (_selectType == _fileOpen) { _mTitleView1.Text = "Open"; } if (_selectType == _fileSave) { _mTitleView1.Text = "Save As"; } if (_selectType == _folderChoose) { _mTitleView1.Text = "Select folder"; } //need to make this a variable Save as, Open, Select Directory _mTitleView1.Gravity = GravityFlags.CenterVertical; //_mTitleView1.SetBackgroundColor(Color.DarkGray); // dark gray -12303292 _mTitleView1.SetTextColor(Color.Black); _mTitleView1.SetPadding((int)SystemHelper.ConvertDpToPixel(_mContext.Resources, 10), (int)SystemHelper.ConvertDpToPixel(_mContext.Resources, 10), 0, (int)SystemHelper.ConvertDpToPixel(_mContext.Resources, 15)); _mTitleView1.SetTextSize(ComplexUnitType.Dip, 18); _mTitleView1.SetTypeface(null, TypefaceStyle.Bold); // Create custom view for AlertDialog title LinearLayout titleLayout1 = new LinearLayout(_mContext); titleLayout1.Orientation = Orientation.Vertical; titleLayout1.AddView(_mTitleView1); if (_selectType == _fileSave) { /////////////////////////////// // Create New Folder Button // /////////////////////////////// Button newDirButton = new Button(_mContext); newDirButton.LayoutParameters = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent); newDirButton.Text = "New Folder"; newDirButton.Click += (sender, args) => { EditText input = new EditText(_mContext); new AlertDialog.Builder(_mContext).SetTitle("New Folder Name").SetView(input).SetPositiveButton("OK", (o, eventArgs) => { String newDirName = input.Text; // Create new directory if (CreateSubDir(_mDir + "/" + newDirName)) { // Navigate into the new directory _mDir += "/" + newDirName; UpdateDirectory(); } else { Toast.MakeText(_mContext, "Failed to create '" + newDirName + "' folder", ToastLength.Short).Show(); } }).SetNegativeButton("Cancel", (o, eventArgs) => { }).Show(); }; titleLayout1.AddView(newDirButton); } ///////////////////////////////////////////////////// // Create View with folder path and entry text box // ///////////////////////////////////////////////////// LinearLayout titleLayout = new LinearLayout(_mContext); titleLayout.Orientation = Orientation.Vertical; var currentSelection = new TextView(_mContext); currentSelection.LayoutParameters = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent); currentSelection.SetTextColor(Color.Black); currentSelection.Gravity = GravityFlags.CenterVertical; currentSelection.Text = "Current selection:"; currentSelection.SetPadding((int)SystemHelper.ConvertDpToPixel(_mContext.Resources, 10), (int)SystemHelper.ConvertDpToPixel(_mContext.Resources, 5), 0, (int)SystemHelper.ConvertDpToPixel(_mContext.Resources, 3)); currentSelection.SetTextSize(ComplexUnitType.Dip, 12); currentSelection.SetTypeface(null, TypefaceStyle.Bold); titleLayout.AddView(currentSelection); _mTitleView = new TextView(_mContext); _mTitleView.LayoutParameters = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent); _mTitleView.SetTextColor(Color.Black); _mTitleView.Gravity = GravityFlags.CenterVertical; _mTitleView.Text = title; _mTitleView.SetPadding((int)SystemHelper.ConvertDpToPixel(_mContext.Resources, 10), 0, (int)SystemHelper.ConvertDpToPixel(_mContext.Resources, 10), (int)SystemHelper.ConvertDpToPixel(_mContext.Resources, 5)); _mTitleView.SetTextSize(ComplexUnitType.Dip, 10); _mTitleView.SetTypeface(null, TypefaceStyle.Normal); titleLayout.AddView(_mTitleView); if (_selectType == _fileOpen || _selectType == _fileSave) { _inputText = new EditText(_mContext); _inputText.Text = DefaultFileName; titleLayout.AddView(_inputText); } ////////////////////////////////////////// // Set Views and Finish Dialog builder // ////////////////////////////////////////// dialogBuilder.SetView(titleLayout); dialogBuilder.SetCustomTitle(titleLayout1); _mListAdapter = CreateListAdapter(listItems); dialogBuilder.SetSingleChoiceItems(_mListAdapter, -1, onClickListener); dialogBuilder.SetCancelable(true); return(dialogBuilder); }