有大神知道为什么点“="号结果出不来吗?我又参照老师的源代码也没有找出错误!求大神帮帮忙
package cn.hp_pc.jisuanji;
import android.content.DialogInterface;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private Button bt_0;//实例化数字按钮
private Button bt_1;//数字按钮
private Button bt_2;//数字按钮
private Button bt_3;//数字按钮
private Button bt_4;//数字按钮
private Button bt_5;//数字按钮
private Button bt_6;//数字按钮
private Button bt_7;//数字按钮
private Button bt_8;//数字按钮
private Button bt_9;//数字按钮
private Button bt_add;//运算符按钮
private Button bt_cut;//
private Button bt_cheng;//
private Button bt_chu;//运算符按钮
private Button bt_point;//小数点按钮
private Button bt_clear;//
private Button bt_del;//
private Button bt_sum;//
private EditText et_input;//显示屏
boolean clear_flag;
public MainActivity() {
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.bt_0=(Button)this.findViewById(R.id.button_0);
this.bt_1=(Button)this.findViewById(R.id.button_1);
this.bt_2=(Button)this.findViewById(R.id.button_2);
this.bt_3=(Button)this.findViewById(R.id.button_3);
this.bt_4=(Button)this.findViewById(R.id.button_4);
this.bt_5=(Button)this.findViewById(R.id.button_5);
this.bt_6=(Button)this.findViewById(R.id.button_6);
this.bt_7=(Button)this.findViewById(R.id.button_7);
this.bt_8=(Button)this.findViewById(R.id.button_8);
this.bt_9=(Button)this.findViewById(R.id.button_9);
this.bt_sum=(Button)this.findViewById(R.id.button_sum);
this.bt_add=(Button)this.findViewById(R.id.button_add);
this.bt_cut=(Button)this.findViewById(R.id.button_cut);
this.bt_cheng=(Button)this.findViewById(R.id.button_cheng);
this.bt_chu=(Button)this.findViewById(R.id.button_chu);
this.bt_point=(Button)this.findViewById(R.id.button_point);
this.bt_clear=(Button)this.findViewById(R.id.button_c);
this.bt_del=(Button)this.findViewById(R.id.button_del);
this.et_input=(EditText)this.findViewById(R.id.et);
//设置按钮点击事件
this.bt_0.setOnClickListener(this);
this.bt_1.setOnClickListener(this);
this.bt_2.setOnClickListener(this);
this.bt_3.setOnClickListener(this);
this.bt_4.setOnClickListener(this);
this.bt_5.setOnClickListener(this);
this.bt_6.setOnClickListener(this);
this.bt_7.setOnClickListener(this);
this.bt_8.setOnClickListener(this);
this.bt_9.setOnClickListener(this);
this.bt_add.setOnClickListener(this);
this.bt_cut.setOnClickListener(this);
this.bt_cheng.setOnClickListener(this);
this.bt_chu.setOnClickListener(this);
this.bt_point.setOnClickListener(this);
this.bt_clear.setOnClickListener(this);
this.bt_del.setOnClickListener(this);
this.bt_sum.setOnClickListener(this);
}
@Override
public void onClick(View view) {
String str=this.et_input.getText().toString();
switch (view.getId()){
case R.id.button_0:
case R.id.button_1:
case R.id.button_2:
case R.id.button_3:
case R.id.button_4:
case R.id.button_5:
case R.id.button_6:
case R.id.button_7:
case R.id.button_8:
case R.id.button_9:
case R.id.button_point:
if(clear_flag)
{
str="";
this.et_input.setText("");
clear_flag=false;
}
this.et_input.setText(str+((Button)view).getText());break;
case R.id.button_add:
case R.id.button_chu:
case R.id.button_cut:
case R.id.button_cheng:
if(clear_flag)
{
this.et_input.setText("");
}else
this.et_input.setText(str+" "+((Button)view).getText()+" ");break;
case R.id.button_c:
clear_flag=false;
this.et_input.setText("");break;
case R.id.button_del:
if(str!=null && !str.equals("")){
this.et_input.setText(str.substring(0,str.length()-1));
}
break;
case R.id.button_sum:
this.getResult();
break;
}
}
private void getResult()
{
clear_flag=true;
String temp=this.et_input.getText().toString();
if(!temp.contains(" ")){
return;
}
if(clear_flag)
{
clear_flag=false;
return;
}
double result=0.0D;
String str1=temp.substring(0,temp.indexOf(32));
String op=temp.substring(temp.indexOf(32)+1,temp.indexOf(32)+2);
String str2=temp.substring(temp.indexOf(32)+3);
double b1 = Double.parseDouble(str1);
double b2 = Double.parseDouble(str2);
if (op.equals("+")) {
result = b1+b2;
} else if (op.equals("-")) {
result = b1-b2;
} else if (op.equals("X")) {
result = b1*b2;
} else if (op.equals("/")) {
if (b2 == 0.0D) {
result = 0.0D;
} else {
result =b1/b2;
}
}
if(!str1.contains(".") && !str2.contains(".")) {
int r = (int)result;
this.et_input.setText(String.valueOf(r));
} else {
this.et_input.setText(String.valueOf(result));
}
}
}