大神帮忙看看,点等号时候输出不了结果额
package com.example.coputer;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends Activity implements OnClickListener{
private Button clear,delete,chu,mutiply,one,two,three,four,
five,senven,six,eight,nine,zero,cut,point,d,add;
boolean clear_flag;
private EditText input;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
/*
* 初始化按钮
*/
clear=(Button) findViewById(R.id.clear);
delete=(Button) findViewById(R.id.delete);
chu=(Button) findViewById(R.id.chu);
mutiply=(Button) findViewById(R.id.mutiply);
one=(Button) findViewById(R.id.one);
two=(Button) findViewById(R.id.two);
three=(Button) findViewById(R.id.three);
four=(Button) findViewById(R.id.four);
five=(Button) findViewById(R.id.five);
six=(Button) findViewById(R.id.six);
senven=(Button) findViewById(R.id.seven);
eight=(Button) findViewById(R.id.eight);
nine=(Button) findViewById(R.id.nine);
zero=(Button) findViewById(R.id.zero);
point=(Button) findViewById(R.id.point);
/*
* 添加单击事件
*/
d=(Button) findViewById(R.id.D);
add=(Button) findViewById(R.id.add);
cut=(Button) findViewById(R.id.cut);;
input=(EditText) findViewById(R.id.input);
clear.setOnClickListener(this);
delete.setOnClickListener(this);
chu.setOnClickListener(this);
mutiply.setOnClickListener(this);
one.setOnClickListener(this);
two.setOnClickListener(this);
three.setOnClickListener(this);
four.setOnClickListener(this);
five.setOnClickListener(this);
senven.setOnClickListener(this);
six.setOnClickListener(this);
eight.setOnClickListener(this);
nine.setOnClickListener(this);
zero.setOnClickListener(this);
cut.setOnClickListener(this);
point.setOnClickListener(this);
d.setOnClickListener(this);
add.setOnClickListener(this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public void onClick(View v) {
String str=input.getText().toString();
switch(v.getId()){
case R.id.zero:
case R.id.one:
case R.id.two:
case R.id.three:
case R.id.four:
case R.id.five:
case R.id.six:
case R.id.seven:
case R.id.eight:
case R.id.nine:
case R.id.point:
if(clear_flag){
str="";
clear_flag=false;
input.setText("");
}
input.setText(str+((Button)v).getText());
break;
case R.id.add:
case R.id.cut:
case R.id.mutiply:
case R.id.chu:
if(clear_flag){
clear_flag=false;
str="";
input.setText("");
}
input.setText(str+" "+((Button)v).getText()+" ");
break;
case R.id.delete:
if(clear_flag){
clear_flag=false;
str="";
input.setText("");
}else if(str!=null&&!str.equals("")){
input.setText(str.substring(0,str.length()-1));
}
break;
case R.id.clear:
clear_flag=false;
str="";
input.setText(" ");
break;
case R.id.D:
getResult();
break;
}
// TODO Auto-generated method stub
}
/*
* 运算结果
*/
private void getResult(){
String str1=input.getText().toString();
if(str1!=null&&!str1.equals("")){
return;
}
if(!str1.contains(" ")){
return;
}if(clear_flag){
clear_flag=false;
return;
}
clear_flag=true;
double result=0;
String str2=str1.substring(0,str1.indexOf(" "));
String op=str1.substring(str1.indexOf(" ")+1,str1.indexOf(" ")+2);
String str3=str1.substring(str1.indexOf(" ")+3);
if(!str2.equals(" ")&&!str3.equals(" ")){
double d2=Double.parseDouble(str2);
double d3=Double.parseDouble(str3);
if(op.equals("+")){
}else if(op.equals("+")){
result=d2+d3;
}else if(op.equals("-")){
result=d2-d3;
}else if(op.equals("*")){
result=d2*d3;
}else if(op.equals("÷")){
if(d3==0){
result=0;
}
else{
result=d2/d3;
}
}
if(!str2.contains(".")&&!str3.contains(".")&&!op.equals("÷")){
int r=(int)(result);
input.setText(r+"");
}else{
input.setText(result+"");
}
}else if(!str2.equals("")&&str3.equals("")){
input.setText(str1);
}else if(str2.equals("")&&!str3.equals("")){
input.setText(str1);
double d3=Double.parseDouble(str3);
if(op.equals("+")){
}else if(op.equals("+")){
result=0+d3;
}else if(op.equals("-")){
result=0-d3;
}else if(op.equals("*")){
result=0;
}else if(op.equals("÷")){
if(d3==0){
result=0;
}
}
if(!str3.contains(".")){
int r=(int)(result);
input.setText(r+"");
}else{
input.setText(result+"");
}
}else{
input.setText("");
}
}
}