et_input不响应?????
package com.example.cs;
import android.app.Activity;
import android.os.Bundle;
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 boolean clear_flag;
@Override
protected void onCreate(Bundle savedInstanceState) {
Button bt0,bt1,bt2,bt3,bt4,bt5,bt6,bt7,bt8,bt9;
Button del,clear,plus,minus,multiply,divide,point,equal;
EditText et_input;
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
bt0=(Button) findViewById(R.id.bt0);
bt1=(Button) findViewById(R.id.bt1);
bt2=(Button) findViewById(R.id.bt2);
bt3=(Button) findViewById(R.id.bt3);
bt4=(Button) findViewById(R.id.bt4);
bt5=(Button) findViewById(R.id.bt5);
bt6=(Button) findViewById(R.id.bt6);
bt7=(Button) findViewById(R.id.bt7);
bt8=(Button) findViewById(R.id.bt8);
bt9=(Button) findViewById(R.id.bt9);
del=(Button) findViewById(R.id.del);
clear=(Button) findViewById(R.id.clear);
plus=(Button) findViewById(R.id.plus);
multiply=(Button) findViewById(R.id.multiply);
divide=(Button) findViewById(R.id.divide);
minus=(Button) findViewById(R.id.minus);
point=(Button) findViewById(R.id.point);
equal=(Button) findViewById(R.id.equal);
et_input=(EditText) findViewById(R.id.et_input);//实例化按钮和显示文本
bt0.setOnClickListener(this);
bt1.setOnClickListener(this);
bt2.setOnClickListener(this);
bt3.setOnClickListener(this);
bt4.setOnClickListener(this);
bt5.setOnClickListener(this);
bt6.setOnClickListener(this);
bt7.setOnClickListener(this);
bt8.setOnClickListener(this);
bt9.setOnClickListener(this);
del.setOnClickListener(this);
clear.setOnClickListener(this);
plus.setOnClickListener(this);
minus.setOnClickListener(this);
multiply.setOnClickListener(this);
divide.setOnClickListener(this);
point.setOnClickListener(this);
equal.setOnClickListener(this);
et_input.setOnClickListener(this);
}
@Override
public void onClick(View v){
String str=et_input.getText().toString();
switch (v.getId()){
case R.id.bt0:
case R.id.bt1:
case R.id.bt2:
case R.id.bt3:
case R.id.bt4:
case R.id.bt5:
case R.id.bt6:
case R.id.bt7:
case R.id.bt8:
case R.id.bt9:
case R.id.point:
if (clear_flag){
clear_flag = false;
et_input.setText("");
}
et_input.setText(str+((Button)v).getText());
break;
case R.id.plus:
case R.id.minus:
case R.id.multiply:
case R.id.divide:
et_input.setText(str+""+((Button)v).getText()+"");
break;
case R.id.clear:
clear_flag = false;
et_input.setText("");
break;
case R.id.del:
if(clear_flag) {
clear_flag = false;
et_input.setText("");
}
if(str!=null&&!str.equals("")) {
et_input.setText(str.substring(0, str.length()-1));
}
break;
case R.id.equal:
getResult();
break;
}
}
private void getResult(){
clear_flag = true;
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;
String s1 = exp.substring(0,exp.indexOf("")); //运算符前面的字符串
String op = exp.substring(exp.indexOf("")+1,exp.indexOf("")+2);//运算符
String s2 = exp.substring(exp.indexOf("")+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("x")) {
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 d3 = Double.parseDouble(s2);
if(op.equals("+")){
result = 0+d3;
}
else if(op.equals("-")){
result = 0-d3;
}
else if(op.equals("x")){
result = 0;
}
else if(op.equals("÷")){
result = 0;
}
if(!s1.contains(".")&&s2.contains(".")){
int r = (int) result;
et_input.setText(r+"");
}
else{
et_input.setText(result+"");
}
}
else{
et_input.setText("");
}
}
}