我正在尝试在 android 中对计算器应用程序进行排序。我的布局设置得很好,现在我只需要执行将计算的代码。应用程序需要在按下时显示数字,然后如果说按下 + 按钮,它将存储第一个数字,将其从屏幕上清除,获取第二个数字,然后将它们相加。当按下相等按钮时,它需要显示结果。
到目前为止我有
public class Calculator extends Activity {
public EditText display;
TextView screen;
int a, result;
int c;
Button b1;
int sum1, sum2;
String r;
public int getSum1(int sum1) {
return sum1;
}
public int getSum2(int sum2) {
return sum2;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public void buttonEventHandler(View v) {
screen=(EditText)findViewById(R.id.screen);
b1=(Button)findViewById(R.id.button1);
switch(v.getId()) {
case R.id.button1 :
screen.setText(screen.getText() + "1");
c = +1;
break;
case R.id.button2 :
screen.setText(screen.getText() + "2");
c = +2;
break;
case R.id.button3 :
screen.setText(screen.getText() + "3");
c = +3;
break;
case R.id.button4 :
screen.setText(screen.getText() + "4");
c = +4;
break;
case R.id.button5 :
screen.setText(screen.getText() + "5");
c = +5;
break;
case R.id.button6 :
screen.setText(screen.getText() + "6");
c = +6;
break;
case R.id.button7 :
screen.setText(screen.getText() + "7");
c = +7;
break;
case R.id.button8 :
screen.setText(screen.getText() + "8");
c = +8;
break;
case R.id.button9 :
screen.setText(screen.getText() + "9");
c = +9;
break;
case R.id.button0 :
screen.setText(screen.getText() + "0");
c = +0;
break;
case R.id.buttonC :
screen.setText(screen.getText() + "");
c = 0;
break;
case R.id.buttonPlus :
case R.id.buttonEquals :
}
}
}
如何进行计算?