Ejemplo n.º 1
0
 private void Init()
 {
     try
     {
         currencies = ConvertionService.GetCurrencies();
     }
     catch (WebException wex)
     {
         currencies = new string[] { GetText(Resource.String.no_currency_msg) };
         Helper.ShowMessageDialog(this, "Error", GetText(Resource.String.network_err_msg));
     }
 }
Ejemplo n.º 2
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

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

            Init();

            Spinner spinner = FindViewById <Spinner>(Resource.Id.currency_spinner);

            textView = FindViewById <TextView>(Resource.Id.result);
            Button   button   = FindViewById <Button>(Resource.Id.btnConvert);
            EditText editText = FindViewById <EditText>(Resource.Id.amount);

            var adapter = new ArrayAdapter <string>(this, Android.Resource.Layout.SimpleSpinnerItem, currencies);

            adapter.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem);
            spinner.Adapter = adapter;

            button.Click += (sender, eventArgs) =>
            {
                try
                {
                    if (!editText.Text.Any(c => char.IsLetter(c)))
                    {
                        string  curr           = spinner.SelectedItem.ToString();
                        decimal amount         = decimal.Parse(editText.Text);
                        string  convertedValue = ConvertionService.ConvertUSD(curr, amount).ToString();
                        textView.SetText($"{convertedValue} {curr}", BufferType.Normal);
                    }
                    else
                    {
                        Toast.MakeText(this, GetText(Resource.String.exploit_msg), ToastLength.Long).Show();
                    }
                }
                catch (WebException)
                {
                    Helper.ShowMessageDialog(this, "Error", GetText(Resource.String.network_err_msg));
                }
                catch (Exception ex)
                {
                    Helper.ShowMessageDialog(this, "Error", GetText(Resource.String.other_error));
                }
            };
        }