private void getResult(){
String exp = et_input.getText().toString();
if(exp==null||exp.equals("")){
return;
}
if(!exp.contains("")){
return;
}
if(clear_flag){
clear_flag = false;
return;
}
clear_flag = true;
double result =0;
int spase = exp.indexOf("");
String s1 = exp.substring(0, spase);//运算符前面的字符串
String op = exp.substring(spase+1,spase+2);//运算符
String s2 = exp.substring(spase+3);//运算符后面的字符串
if(!s1.equals("")&&!s2.equals("")){ //第一种运算情况
double d1 = Double.parseDouble(s1);
double d2 = Double.parseDouble(s2);
if(op.equals("+")){
result = d1+d2;
}else if(op.equals("-")){
result = d1-d2;
}else if(op.equals("×")){
result = d1*d2;
}else if(op.equals("÷")){
if(d2==0){
result = 0;
}else{
result = d1/d2;
}
}
if(!s1.contains(".")&&!s2.contains(".")){
int r = (int) result;
et_input.setText(r+"");
}else{
et_input.setText(result+"");
}
}else if(!s1.equals("")&&s2.equals("")){ //第二种运算情况
et_input.setText(exp);
}else if(s1.equals("")&&!s2.equals("")){ //第三种运算情况
double d2 = Double.parseDouble(s2);
if(op.equals("+")){
result = 0+d2;
}else if(op.equals("-")){
result = 0-d2;
}else if(op.equals("×")){
result = 0;
}else if(op.equals("÷")){
result = 0;
}
if(!s2.contains(".")){
int r = (int) result;
et_input.setText(r+"");
}else{
et_input.setText(result+"");
}
}else{ //第四种运算
et_input.setText("");
}
}