Skip to content

Instantly share code, notes, and snippets.

@ytabuchi
Last active September 15, 2015 06:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ytabuchi/fcede2638ad8728bceb0 to your computer and use it in GitHub Desktop.
Save ytabuchi/fcede2638ad8728bceb0 to your computer and use it in GitHub Desktop.
この例はAndroidですが他のOSでも一緒ですね。TextBlock/EditText(Decimalに入力制限済み) から Text を引っ張ってきて、数値に変換して計算に投げて結果を得る。
Spinner spinner;
EditText tbX;
EditText tbY;
TextView tvResult;
button.Click += (sender, e) => {
double xValue;
double yValue;
double resValue;
double number;
xValue = double.TryParse(tbX.Text, out number) ? number : 0;
yValue = double.TryParse(tbY.Text, out number) ? number : 0;
if (xValue != 0 || yValue != 0)
{
var spnValue = spinner.SelectedItem.ToString();
resValue = (spnValue == "+") ? calc.Plus(xValue, yValue) : calc.Minus(xValue, yValue);
tvResult.Text = string.Format($"{xValue} {spnValue} {yValue} = {resValue}");
}
else
{
Toast.MakeText(this, "Please input numbers other than 0", ToastLength.Short).Show();
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment