b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (e1.getText().toString().isEmpty()||e2.getText().toString().isEmpty()) {
Toast.makeText(MainActivity.this, "空", Toast.LENGTH_SHORT).show();
}
else if (r1.isChecked()) {
Double wb1 = Double.parseDouble(e1.getText().toString());
Double wb2 = Double.parseDouble(e2.getText().toString());
Double result = wb1 +wb2;
t1.setText(result.toString());
} else if (r2.isChecked()) {
Double wb1 = Double.parseDouble(e1.getText().toString());
Double wb2 = Double.parseDouble(e2.getText().toString());
Double result = wb1 - wb2;
t1.setText(result.toString());
} else {
AlertDialog.Builder dlg = new AlertDialog.Builder(MainActivity.this);
dlg.setTitle("错误error");
dlg.setMessage("请检查控件或文本框有没有被输入和选中");
dlg.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
dlg.show();
}
打开App,阅读手记