Last active
September 15, 2015 06:21
-
-
Save ytabuchi/fcede2638ad8728bceb0 to your computer and use it in GitHub Desktop.
この例はAndroidですが他のOSでも一緒ですね。TextBlock/EditText(Decimalに入力制限済み) から Text を引っ張ってきて、数値に変換して計算に投げて結果を得る。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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