0

我正在为 android 使用单声道,我试图弄清楚如何在每 100 次单击按钮后添加一个对话框,代码看起来像这样,程序已经计算了每次单击按钮。我在想一个if语句?

button.Click += delegate { button.Text = string.Format("{0} clicks!", count++); };

if(count >= 5)

            {                
                var builder = new AlertDialog.Builder(this);
                builder.SetMessage("Your On Your Way");
                builder.SetCancelable(false);
                builder.SetPositiveButton("OK", delegate { });
                var dialog = builder.Create();
                dialog.Show();

            }
4

1 回答 1

0

您可以将 if 语句放在按钮的委托中:

button.Click += delegate
            {
                button.Text = string.Format("{0} clicks!", count++);

                if (count % 100 == 0)
                {
                    var builder = new AlertDialog.Builder(this);
                    builder.SetMessage("Your On Your Way");
                    builder.SetCancelable(false);
                    builder.SetPositiveButton("OK", delegate { });
                    builder.Show();
                }

            };
于 2012-12-07T17:53:27.870 回答