1.首先处理button按钮事件,且把值传给第二个activity
2.第二个activity接收值并显示出来
button.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
if (edit.getText().toString().equals("") || edit.getText().toString()== null) {
Toast.makeText(MainActivity.this, "没有体重值,请输入体重值",
Toast.LENGTH_LONG).show();//在acitivity中显示话
} else {
if (radio1.isChecked()) {
sex = radio1.getText().toString();
} else {
sex = ((RadioButton) findViewById(R.id.radio2))
.getText().toString();
}// 这个是性别
// 身高
height = edit.getText().toString();
// TODO Auto-generated method stub
Intent intent = new Intent();
intent.setClass(MainActivity.this, AnotherActivity.class);
intent.putExtra("sex", sex);
intent.putExtra("height", height);
startActivity(intent);
// MainActivity.this.finish();当前页面结束
}
}
});
}
Intent intent=this.getIntent();//创建intent接收mainactivity传来的参数
sex=intent.getStringExtra("sex");//将传过来的值传给变量sex
height=intent.getStringExtra("height");
if(sex.equals("男")){
height1=(Integer.parseInt(height)-80)*0.7;
}
else{
height1=(Integer.parseInt(height)-70)*0.6;
}
texts.setText("你是一位"+sex+"性"+"\n"+"你的身高是"+height+"\n"+"你的标准体重为"+height1+"公斤");