ITPub博客

首页 > IT职业 > IT职场 > 安卓Android

安卓Android

IT职场 作者:mocow 时间:2021-09-09 10:29:12 0 删除 编辑

图片描述

图片描述

图片描述

图片描述

图片描述

图片描述

图片描述

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();
        }


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/2815/viewspace-2822619/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-04-17

  • 博文量
    108
  • 访问量
    1365