예제 #1
0
        public static async Task <int> ShowSingleChoiseDlg(Context context, string title, IListAdapter items, bool bAllowAbort = true)
        {
            if (context == null)
            {
                return(-1);
            }

            tcsScDlg = new TaskCompletionSource <int>();

            MainThread.BeginInvokeOnMainThread(() =>
            {
                try
                {
                    var builder = new AlertDialog.Builder(context).SetTitle(title);
                    if (bAllowAbort)
                    {
                        builder = builder.SetNegativeButton(context.Resources.GetString(context.Resources.GetIdentifier("action_abort", "string", "me.ichrono.droid")), (s, e) => { tcsScDlg.TrySetResult(-1); });
                    }
                    builder = builder.SetSingleChoiceItems(items, -1, new SingleChoiceClickListener(tcsScDlg));
                    builder = builder.SetOnCancelListener(new myDialogCancelListener <int>(tcsScDlg));
                    var dlg = builder.Create();

                    dlg.Show();
                }
                catch
                {
                    tcsScDlg.TrySetResult(-1);
                }
            });
            await tskScDlg;

            return(tskScDlg.Result);
        }