运行效果图
核心代码
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;
}
}
遇到的问题
老是出错,还很难找出来在哪里,一个优秀的室友真的是无比的重要。。。。
还有一定要记清楚自己定义的每一个词