身高体重计量器
来源:互联网 发布:程序员论坛排名 编辑:程序博客网 时间:2024/04/29 21:58
<span style="font-family: Arial, Helvetica, sans-serif;"></span><pre name="code" class="plain">
activity_show.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:background="@android:color/holo_green_light"> <TextView android:id="@+id/tvResult" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="10dip" android:textSize="20dip"/></LinearLayout>
activity_main.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_marginTop="20dip" android:gravity="center_horizontal" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="个人标准身高计算器" android:textSize="22dip" android:textStyle="bold" ></TextView> </LinearLayout> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_marginTop="10dip" > <TextView android:layout_width="120dip" android:layout_height="wrap_content" android:text="请输入你的身高:" android:layout_marginLeft="5dip"/> <EditText android:layout_width="150dip" android:id="@+id/etWeight" android:layout_height="wrap_content" android:inputType="number"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="cm"/> </LinearLayout> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal"> <TextView android:layout_width="120dip" android:layout_height="wrap_content" android:text="请选择你的性别:" android:layout_marginLeft="5dip"/> <CheckBox android:id="@+id/chMan" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="男"/> <CheckBox android:id="@+id/chWoman" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="女"/> </LinearLayout> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:gravity="center_horizontal"> <Button android:layout_marginTop="20dip" android:layout_width="200dip" android:layout_height="wrap_content" android:id="@+id/buCalculator" android:text="运算"/> </LinearLayout> </LinearLayout>MainActivity
package com.example.heightcalculatorpro;import android.os.Bundle;import android.app.Activity;import android.content.Intent;import android.view.Menu;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.CheckBox;import android.widget.EditText;import android.widget.TextView;import android.widget.Toast;public class MainActivity extends Activity {private Button buCalculator;private CheckBox chWoman;private CheckBox chMan;private EditText etWeight; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); buCalculator = (Button) findViewById(R.id.buCalculator); chWoman = (CheckBox) findViewById(R.id.chWoman); chMan = (CheckBox) findViewById(R.id.chMan); etWeight = (EditText) findViewById(R.id.etWeight); buCalculator.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {// TODO Auto-generated method stubresult();}}); } public void result(){ double high = Double.parseDouble(etWeight.getText().toString()); double standardWeight = 0; String sex = null; if(!etWeight.getText().toString().equals("")){ if(chMan.isChecked()){ standardWeight = (high-80)*0.7; sex = "男"; }else if(chWoman.isChecked()){ standardWeight =(high-70)*0.6; sex = "女"; }else{ Toast.makeText(MainActivity.this, "请选择性别", Toast.LENGTH_LONG); } }else{ Toast.makeText(MainActivity.this, "请输入身高", Toast.LENGTH_LONG); } Intent intent = new Intent();Bundle bundle = new Bundle();bundle.putDouble("high", high);bundle.putDouble("standardWeight",standardWeight);bundle.putString("sex",sex);intent.putExtras(bundle);intent.setClass(this, ShowActivity.class);startActivity(intent); } }
ShowActivity
package com.example.heightcalculatorpro;import android.app.Activity;import android.os.Bundle;import android.widget.TextView;public class ShowActivity extends Activity{private TextView tvResult;@Overrideprotected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.onCreate(savedInstanceState);setContentView(R.layout.activity_show);Bundle bundle = getIntent().getExtras();String sex = bundle.getString("sex");double high = bundle.getDouble("high");double standardWeight = bundle.getDouble("standardWeight");tvResult = (TextView) findViewById(R.id.tvResult);tvResult.setText("你是一位"+sex+"性\n你的身高是"+high+"\n你的标准体重是"+Math.abs(standardWeight));}}
0 0
- 身高体重计量器
- 身高
- 古代人身高
- 平均身高
- 身高预测
- 女儿身高
- 女儿身高
- 女儿身高
- 奶牛身高
- 实习小记 C#连接体重计串口通讯小结
- 华为机试 - 身高差最小身高
- 根据父母身高计算儿子身高
- 男女身高配对
- 我靠,身高!
- 爱情与身高
- C++自编身高
- 身高转英尺
- 身高与脚长
- 贪心 10 15
- react-native 错误捕捉与处理
- 【Some】【公司】为啥公司愿花更多钱从外面招人
- 2016-3-21机试第一道题
- 计算几何速成
- 身高体重计量器
- 数据库索引
- 关于python文件操作
- 编码URLEncoder和解码URLDecoder UTF-8到GBK的转码
- Python 数据结构与算法——tree(树)
- ACM-problem Q
- 贪心 1016
- 关于ScrollView 与ListView的 之间存在的兼容性问题
- Python 进阶——重访 list