Skip to content

Commit 65bbff6

Browse files
committed
fix something
1 parent 7499863 commit 65bbff6

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

AndroidCalculator/MainActivity.cs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ public class MainActivity : Activity
1414
{
1515
private bool IsCalculateOver=false;
1616
private string ExpressString ="";
17+
private EditText txtInner = null;
18+
private EditText txtSurface = null;
1719
protected override void OnCreate(Bundle bundle)
1820
{
1921
base.OnCreate(bundle);
@@ -39,7 +41,7 @@ protected override void OnCreate(Bundle bundle)
3941
btnOne.Click += delegate { Click("1"); };
4042
Button btnTwo = FindViewById<Button>(Resource.Id.btnTwo);
4143
btnTwo.Click += delegate { Click("2"); };
42-
Button btnThree = FindViewById<Button>(Resource.Id.btnThree);
44+
Button btnThree = FindViewById<Button>(Resource.Id.btnThree);
4345
btnThree.Click += delegate { Click("3"); };
4446
Button btnRightBracket = FindViewById<Button>(Resource.Id.btnRightBracket);
4547
btnRightBracket.Click += delegate { Click("("); };
@@ -63,10 +65,11 @@ protected override void OnCreate(Bundle bundle)
6365
btnEqual.Click += delegate { Equal(); };
6466
Button btnClear = FindViewById<Button>(Resource.Id.btnClear);
6567
btnClear.Click += delegate { Clear(); };
68+
txtInner = FindViewById<EditText>(Resource.Id.txtInner);
69+
txtSurface = FindViewById<EditText>(Resource.Id.txtSurface);
6670
}
6771
private void Click(string Tag)
6872
{
69-
EditText txtInner = FindViewById<EditText>(Resource.Id.txtInner);
7073
if (!ExpressString.Equals("") && IsCalculateOver)
7174
{
7275
IsCalculateOver = false;
@@ -76,23 +79,20 @@ private void Click(string Tag)
7679
}
7780
private void Back()
7881
{
79-
EditText txtInner = FindViewById<EditText>(Resource.Id.txtInner);
8082
if(!txtInner.Text.Equals(""))
8183
{
82-
txtInner.Text = txtInner.Text.Substring(0, txtInner.Text.Length-1);
84+
txtInner.Text = txtInner.Text.PadRight(1);
8385
}
8486
}
8587
private void Equal()
8688
{
87-
EditText txtInner=FindViewById<EditText>(Resource.Id.txtInner);
88-
EditText txtSurface = FindViewById<EditText>(Resource.Id.txtSurface);
8989
if(!txtInner.Text.Equals(""))
9090
{
9191
try
92-
{
92+
{
9393
StringCalculate Parse = new StringCalculate();
94-
string Result =Parse.runExpress(txtInner.Text);
95-
double Number=Convert.ToDouble(Result);
94+
var Result =Parse.runExpress(txtInner.Text);
95+
var Number = Convert.ToDecimal(Result);
9696
txtSurface.Text = Number.ToString();
9797
IsCalculateOver = !IsCalculateOver;
9898
ExpressString = Result;
@@ -106,15 +106,13 @@ private void Equal()
106106
}
107107
private void SameAsPrevious(string Sign)
108108
{
109-
EditText txtInner = FindViewById<EditText>(Resource.Id.txtInner);
110-
if(txtInner.Text.Length>1&&txtInner.Text.Substring(txtInner.Text.Length-2,1).Equals(Sign))
109+
if(txtInner.Text.Length>1&&txtInner.Text.PadRight(1).Equals(Sign))
111110
{
112-
txtInner.Text= txtInner.Text.Substring(0, txtInner.Text.Length - 1);
111+
txtInner.Text= txtInner.Text.PadLeft(txtInner.Text.Length-1);
113112
}
114113
}
115114
private void Clear()
116115
{
117-
EditText txtInner = FindViewById<EditText>(Resource.Id.txtInner);
118116
txtInner.Text = "";
119117
}
120118
}

0 commit comments

Comments
 (0)