Exemplo n.º 1
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // 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
            Button   button         = FindViewById <Button>(Resource.Id.myButton);
            EditText amountEditText = FindViewById <EditText>(Resource.Id.editTextAmount);
            TextView resultTextView = FindViewById <TextView>(Resource.Id.textViewResult);

            button.Click += delegate {
                var input = amountEditText.Text;
                try {
                    var conversion = CurrencyConverter.ConvertDollarsToPunds(input);
                    resultTextView.Text = StringLib.DollarToPunds(input, conversion);
                } catch (FormatException fe) {
                    // Show error message
                    Toast.MakeText(this, StringLib.CONVERSION_ERROR_MESSAGE, ToastLength.Short).Show();
                    Console.WriteLine(fe);
                }
            };
        }
Exemplo n.º 2
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            Button.TouchUpInside += delegate {
                var input = amountTextField.Text;
                try {
                    var conversion = CurrencyConverter.ConvertDollarsToPunds(input);
                    resultLabel.Text = StringLib.DollarToPunds(input, conversion);
                } catch (FormatException fe) {
                    // Show error message
                    var ac = UIAlertController.Create(StringLib.CONVERSION_ERROR_TITLE, StringLib.CONVERSION_ERROR_MESSAGE, UIAlertControllerStyle.Alert);
                    ac.AddAction(UIAlertAction.Create(StringLib.OK, UIAlertActionStyle.Default, delegate {
                        // This is called after the user clicked on ok. Reset input text field
                        amountTextField.Text = "";
                    }));
                    PresentViewController(ac, true, null);
                    Console.WriteLine(fe);
                }
            };
        }