任务二计算标准体重

运行效果图

核心代码

package com.example.standarweight;

import android.R.string;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class ShowActivity extends Activity{
	private TextView tvShowTall;
	String sex;
	double tall;
	double weight;
	protected void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_show);
		getData();
		initViews();
		bindData();
		
		
	}
	
	
	private void getData() {
		// TODO Auto-generated method stub
		Bundle bundle=getIntent().getExtras();
		sex=bundle.getString("sex");
		tall=bundle.getDouble("tall");
		if(sex.equals("男"))
			weight=(tall-80)*0.7;
		else
			weight=(tall-70)*0.6;
		
		
		
	}
	private void initViews() {
		tvShowTall=(TextView)findViewById(R.id.tvShowTall);
	}
	private void bindData(){
		tvShowTall.setText("你是一位"+sex+"性"+"\n你的身高是"+tall+"厘米\n你的标准体重是"+weight+"千克。");
	}
	

}




package com.example.standarweight;

import android.R.string;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
import android.widget.RadioButton;

public class MainActivity extends Activity {
	private RadioButton rbMan;
	private RadioButton rabWoman;
	private EditText etTall;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        rbMan=(RadioButton)findViewById(R.id.rbMan);
        rabWoman=(RadioButton)findViewById(R.id.rbWoman);
        etTall=(EditText)findViewById(R.id.etTall);
    }
    public void calculate(View view){
    	String sex;
    	double tall = 0;
    	if(rbMan.isChecked())
    		sex=rbMan.getText().toString();
    	else
    		sex=rabWoman.getText().toString();
    	double hight=Double.parseDouble(etTall.getText().toString());
    	Intent intent=new Intent();
    	intent.setClass(this, ShowActivity.class);
    	Bundle bundle=new Bundle();
    	bundle.putString("sex", sex);
		bundle.putDouble("tall",hight);
    	intent.putExtras(bundle);
    	startActivity(intent);
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
    
}

遇到的问题
老是出错,还很难找出来在哪里,一个优秀的室友真的是无比的重要。。。。
还有一定要记清楚自己定义的每一个词

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值