public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            TipCalculator calc = new TipCalculator();

            calculateButton.TouchUpInside += (object sender, EventArgs e) =>
            {
                tipAmountLabel.Text = calc.calculateTip(billAmountTextField.Text, tipPercentageTextField.Text);
            };

            billAmountTextField.AddTarget((sender, e) =>
            {
                tipAmountLabel.Text = calc.calculateTip(billAmountTextField.Text, tipPercentageTextField.Text);
            }, UIControlEvent.EditingChanged);

            tipPercentageTextField.AddTarget((sender, e) =>
            {
                tipAmountLabel.Text = calc.calculateTip(billAmountTextField.Text, tipPercentageTextField.Text);
            }, UIControlEvent.EditingChanged);

            tipPercentageSlider.ValueChanged += (sender, e) =>
            {
                int tipPercentage = (int)tipPercentageSlider.Value;

                tipPercentageTextField.Text = tipPercentage.ToString();
                tipAmountLabel.Text         = calc.adjustTipPercentage(billAmountTextField.Text, tipPercentage);
            };
        }
Exemplo n.º 2
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            TipCalculator calc = new TipCalculator();

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            // Get our button from the layout resource,
            // and attach an event to it
            TextView tipAmountResult        = FindViewById <TextView>(Resource.Id.tipAmountResult);
            EditText billAmountTextField    = FindViewById <EditText>(Resource.Id.billAmountText);
            EditText tipPercentageTextField = FindViewById <EditText>(Resource.Id.tipPercentageText);
            SeekBar  tipSeekBar             = FindViewById <SeekBar>(Resource.Id.tipSeekBar);


            Button calculateButton = FindViewById <Button>(Resource.Id.calculateButton);

            calculateButton.Click += (sender, e) =>
            {
                tipAmountResult.Text = calc.calculateTip(billAmountTextField.Text, tipPercentageTextField.Text);
            };

            billAmountTextField.TextChanged += (sender, e) =>
            {
                tipAmountResult.Text = calc.calculateTip(billAmountTextField.Text, tipPercentageTextField.Text);
            };

            tipPercentageTextField.TextChanged += (sender, e) =>
            {
                tipAmountResult.Text = calc.calculateTip(billAmountTextField.Text, tipPercentageTextField.Text);
            };

            tipSeekBar.ProgressChanged += (sender, e) =>
            {
                int tipPercentage = (int)tipSeekBar.Progress;

                tipPercentageTextField.Text = tipPercentage.ToString();
                tipAmountResult.Text        = calc.adjustTipPercentage(billAmountTextField.Text, tipPercentage);
            };
        }