手记

ad

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


0人推荐
随时随地看视频
慕课网APP