继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

ad

bobbi黑色非凡
关注TA
已关注
手记 4
粉丝 0
获赞 0
package com.example.administrator.testxwh;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
    Button btn1;
    EditText ed1,ed2;
    RadioButton rb1,rb2;
    TextView tv1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        btn1= (Button) findViewById(R.id.button);
        ed1= (EditText) findViewById(R.id.editText);
        ed2= (EditText) findViewById(R.id.editText2);
        rb1= (RadioButton) findViewById(R.id.radioButton);
        rb2= (RadioButton) findViewById(R.id.radioButton2);
        tv1= (TextView) findViewById(R.id.textView3);

        btn1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {


                String s1,s2;
                s1=ed1.getText().toString();
                s2=ed2.getText().toString();

                if(s1.equals("")||s2.equals(""))
                {
                    Toast.makeText(MainActivity.this, "输入不能为空", Toast.LENGTH_SHORT).show();
                }
                else
                {
                    int a1, a2;
                    a1 = Integer.parseInt(s1);
                    a2 = Integer.parseInt(s2);
                    int res=0;

                    if(rb1.isChecked())
                    {
                        res = a1 + a2;
                    }
                    else if (rb2.isChecked())
                    {
                        res = a1 - a2;
                    }
                    else
                    {
                            Toast.makeText(MainActivity.this, "请选择运算类型", Toast.LENGTH_SHORT).show();
                    }
                    Intent i=new Intent(MainActivity.this,SecondActivity.class);
                    i.putExtra("a1",res);
                    startActivity(i);
                }
            }
        });
    }
}

https://img4.mukewang.com/5cb555f60001551a09890718.jpg

https://img.mukewang.com/5cb555f60001a84d19190989.jpg

https://img4.mukewang.com/5cb555f60001d27d13780786.jpg


打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP