Есть код Калькулятора на Xamarin. Код разметки думаю не имеет смысла. Привожу код C#. Все работает, кроме вывода Result. Не могу понять, как его реализовать.
using System;
using System.Globalization;
using System.Text.RegularExpressions;
using Android.App;
using Android.Widget;
using Android.OS;
using static System.Double;
using System.Linq.Expressions;
namespace AndroidCalculator
{
[Activity(Label = "Android Calculator", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Main);
Button button0 = FindViewById<Button>(Resource.Id.button0);
Button button1 = FindViewById<Button>(Resource.Id.button1);
Button button2 = FindViewById<Button>(Resource.Id.button2);
Button button3 = FindViewById<Button>(Resource.Id.button3);
Button button4 = FindViewById<Button>(Resource.Id.button4);
Button button5 = FindViewById<Button>(Resource.Id.button5);
Button button6 = FindViewById<Button>(Resource.Id.button6);
Button button7 = FindViewById<Button>(Resource.Id.button7);
Button button8 = FindViewById<Button>(Resource.Id.button8);
Button button9 = FindViewById<Button>(Resource.Id.button9);
Button buttonMultiply = FindViewById<Button>(Resource.Id.buttonMultiply);
Button buttonDivision = FindViewById<Button>(Resource.Id.buttonDivision);
Button buttonSubtraction = FindViewById<Button>(Resource.Id.buttonSubtraction);
Button buttonAddition = FindViewById<Button>(Resource.Id.buttonAddition);
Button buttonResult = FindViewById<Button>(Resource.Id.buttonResult);
Button buttonPoint = FindViewById<Button>(Resource.Id.buttonPoint);
Button buttonClear = FindViewById<Button>(Resource.Id.buttonClear);
EditText editTextOperate = FindViewById<EditText>(Resource.Id.editTextOperate);
TextView textViewResult = FindViewById<TextView>(Resource.Id.textViewResult);
buttonPoint.Click += delegate
{
if (editTextOperate.Text.Trim().EndsWith("."))
{
editTextOperate.Text += "";
}
else if (editTextOperate.Text.Trim().Length != 0)
{
editTextOperate.Text += ".";
}
};
button1.Click += delegate
{
editTextOperate.Text += "1";
};
button2.Click += delegate
{
editTextOperate.Text += "2";
};
button3.Click += delegate
{
editTextOperate.Text += "3";
};
button4.Click += delegate
{
editTextOperate.Text += "4";
};
button5.Click += delegate
{
editTextOperate.Text += "5";
};
button6.Click += delegate
{
editTextOperate.Text += "6";
};
button7.Click += delegate
{
editTextOperate.Text += "7";
};
button8.Click += delegate
{
editTextOperate.Text += "8";
};
button9.Click += delegate
{
editTextOperate.Text += "9";
};
button0.Click += delegate
{
editTextOperate.Text += "0";
};
buttonAddition.Click += delegate
{
if (editTextOperate.Text.Length != 0)
{
editTextOperate.Text += " + ";
}
};
buttonSubtraction.Click += delegate
{
if (editTextOperate.Text.Length != 0)
{
editTextOperate.Text += " - ";
}
};
buttonMultiply.Click += delegate
{
if (editTextOperate.Text.Length != 0)
{
editTextOperate.Text += " * ";
}
};
buttonDivision.Click += delegate
{
if (editTextOperate.Text.Length != 0)
{
editTextOperate.Text += " / ";
}
};
Regex regex = new Regex(@"^-?\d*\.?\d*");
buttonResult.Click += delegate
{
if (editTextOperate.Text != string.Empty & regex.IsMatch(editTextOperate.Text))
{
double result = Math.Sqrt(Parse(editTextOperate.Text.Trim()));
textViewResult.Text = Convert.ToString(result, CultureInfo.InvariantCulture);
}
};
buttonClear.Click += delegate
{
ClearDisplay(editTextOperate, textViewResult);
};
}
private void ClearDisplay(EditText editTextOperate, TextView textViewResult)
{
editTextOperate.Text = string.Empty;
textViewResult.Text = string.Empty;
}
}
}
Реализовал к примеру в Result вывод Sqrt от числа, все работает, а если например при сложении, умножении и тд, не могу сообразить