使用edittext输出为什么结果有问题?
private RadioButton radio1,radio2;
private Button button;
private TextView text;
private RadioGroup rg;
private EditText edit;
private String str,cal;
private double mon;
private int choose;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
radio1 = (RadioButton) findViewById(R.id.r1);
radio2 = (RadioButton) findViewById(R.id.r2);
button = (Button) findViewById(R.id.but);
rg = (RadioGroup) findViewById(R.id.rg);
text = (TextView) findViewById(R.id.tv);
edit = (EditText) findViewById(R.id.et);
rg.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
if(R.id.r1==checkedId){
Toast tot1=Toast.makeText(MainActivity.this, "请输入vip顾客金额", Toast.LENGTH_SHORT);
tot1.setGravity(Gravity.CENTER, 0, 0);
tot1.show();
choose = 1;
cal = radio1.getText().toString();
}else if(R.id.r2==checkedId){
str=edit.getText().toString();
Toast tot = Toast.makeText(MainActivity.this, "请输入普通顾客金额", Toast.LENGTH_SHORT);
tot.setGravity(Gravity.CENTER, 0, 0);
tot.show();
choose = 2;
cal = radio2.getText().toString();
}
}
});
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
str = edit.getText().toString();
if(choose == 1){
mon = Double.parseDouble(str)*0.8;
}else if(choose == 2){
mon = Double.parseDouble(str);
}
text.setText("类别:"+ cal +"顾客 "+" 金额:"+mon);
}
});
}