BMI计算器所实现的内容

1.两个页面的跳转

a.intent组件

2.根据所选单选框中的按钮进行BMI指数的判断

a.单选按钮监听

具体代码呈现

bmicalculate.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:background="#FFE4C4"android:orientation="vertical">
<!--    "体重(kg)/身高(m)平方"--><TextViewandroid:layout_width="match_parent"android:layout_height="wrap_content"android:text="BMI体质指数计算"android:textSize="30dp"android:gravity="center"/><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"><EditTextandroid:id="@+id/tizhong"android:layout_width="match_parent"android:layout_height="match_parent"android:selectAllOnFocus="true"android:hint="请输入您的体重(kg)"android:textSize="20dp"android:inputType="numberDecimal"></EditText></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal"><EditTextandroid:id="@+id/shengao"android:layout_width="match_parent"android:layout_height="match_parent"android:selectAllOnFocus="true"android:hint="请输入您的身高(m)"android:textSize="20dp"android:inputType="numberDecimal"></EditText></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"><RadioGroupandroid:id="@+id/group"android:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal"><RadioButtonandroid:id="@+id/WHO"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="WHO标准"android:textSize="17dp"></RadioButton><RadioButtonandroid:id="@+id/ya"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="亚洲标准(中国除外)"android:textSize="17dp"></RadioButton><RadioButtonandroid:id="@+id/china"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="中国标准"android:textSize="17dp"></RadioButton></RadioGroup></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"><Buttonandroid:id="@+id/calculate"android:layout_width="match_parent"android:layout_height="wrap_content"android:onClick="onClick"android:text="计算"android:textSize="20dp"></Button></LinearLayout><LinearLayoutandroid:layout_width="wrap_content"android:layout_height="wrap_content"><ImageViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:src="@drawable/bmi"></ImageView></LinearLayout>
</LinearLayout>

MainActivity.java

package com.example.study;import androidx.appcompat.app.AppCompatActivity;import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;import java.text.DecimalFormat;public class MainActivity extends AppCompatActivity {int one=0,two=0,three=0;private  Button calculate;private EditText shengao;private EditText tizhong;private TextView jieguo;private RadioButton WHO;private RadioButton ya;private RadioButton china;private RadioGroup group;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.bmicalculate);//单选框group = (RadioGroup)this.findViewById(R.id.group);WHO = (RadioButton)this.findViewById(R.id.WHO);ya = (RadioButton)this.findViewById(R.id.ya);china = (RadioButton)this.findViewById(R.id.china);group.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {@Overridepublic void onCheckedChanged(RadioGroup Group, int checkedId) {switch (checkedId){case R.id.WHO:one=1 ;two=0;three=0;Toast.makeText(getApplicationContext(),"选的为WHO", Toast.LENGTH_SHORT).show();break;case R.id.ya:two=1;one=0;three=0;Toast.makeText(getApplicationContext(),"选的为亚洲标准(中国除外)", Toast.LENGTH_SHORT).show();break;case R.id.china:three=1;one=0;two=0;Toast.makeText(getApplicationContext(),"选的为中国标准", Toast.LENGTH_SHORT).show();break;}}});calculate = (Button)findViewById(R.id.calculate);calculate.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view) {tizhong = (EditText)findViewById(R.id.tizhong);double b=Double.parseDouble(tizhong.getEditableText().toString().trim());shengao = (EditText)findViewById(R.id.shengao);double c=Double.parseDouble(shengao.getEditableText().toString().trim());double BMI =  (b/(c*c));DecimalFormat BMI1 = new DecimalFormat("#.0");jieguo = (TextView) findViewById(R.id.jieguo);Intent intent = new Intent(MainActivity.this,MainActivity2.class);intent.putExtra("endjieguo",BMI);intent.putExtra("cone",one);intent.putExtra("ctwo",two);intent.putExtra("cthree",three);intent.putExtra("ctizhong",b);intent.putExtra("cshengao",c);startActivity(intent);}});}
}

activity_main2.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"tools:context=".MainActivity2">
<TextViewandroid:id="@+id/input"android:layout_width="match_parent"android:layout_height="wrap_content"android:text="欢迎"android:textSize="40dp"android:gravity="center"></TextView>
</LinearLayout>

MainActivity.java

package com.example.study;import androidx.appcompat.app.AppCompatActivity;import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;import java.text.DecimalFormat;public class MainActivity2 extends AppCompatActivity {private TextView textView;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main2);textView = findViewById(R.id.input);Intent intent = getIntent();String cone = String.valueOf(intent.getIntExtra("cone",0));Double cone1 = Double.parseDouble(cone);String ctwo = String.valueOf(intent.getIntExtra("ctwo",0));Double ctwo1 = Double.parseDouble(ctwo);String cthree = String.valueOf(intent.getIntExtra("cthree",0));Double cthree1 = Double.parseDouble(cthree);String cshengao = String.valueOf(intent.getDoubleExtra("cshengao",1));Double cshengao1 = Double.parseDouble(cshengao);DecimalFormat cshengao2 = new DecimalFormat("#.00");String ctizhong = String.valueOf(intent.getDoubleExtra("ctizhong",1));Double ctizhong1 = Double.parseDouble(ctizhong);DecimalFormat ctizhong2 = new DecimalFormat("#.00");String endjieguo = String.valueOf(intent.getDoubleExtra("endjieguo",1));Double endjieguo2 = Double.parseDouble(endjieguo);DecimalFormat endjieguo1 = new DecimalFormat("#.0");Double shu = Double.valueOf(String.valueOf(endjieguo1.format(endjieguo2)));String panduan = "";if(cone1>0){if (shu <= 18.5){panduan = "体重过低";}if (shu >18.5 && shu< 24.9){panduan = "体重属于正常范围";}if (shu>=25.0 && shu< 30){panduan = "体重超重";}if (shu>=30  ){panduan = "体重肥胖";}textView.setText("根据"+"WHO国际标准"+String.valueOf(cshengao2.format(cshengao1))+"身高"+String.valueOf(ctizhong2.format(ctizhong1))+"KG体重"+"BMI指数为"+String.valueOf(endjieguo1.format(endjieguo2))+panduan);}if(ctwo1>0){if (shu <= 18.5){panduan = "体重过低";}if (shu >18.5 && shu< 22.9){panduan = "体重属于正常范围";}if (shu>=23.0 && shu< 25){panduan = "体重超重";}if (shu>=25  ){panduan = "体重肥胖";}textView.setText("根据"+"亚洲标准(中国除外)"+String.valueOf(cshengao2.format(cshengao1))+"M的身高"+String.valueOf(ctizhong2.format(ctizhong1))+"KG的体重"+"BMI指数为"+String.valueOf(endjieguo1.format(endjieguo2))+panduan);}if(cthree1>0){if (shu <= 18.5){panduan = "体重过低";}if (shu >18.5 && shu< 23.9){panduan = "体重属于正常范围";}if (shu>=24.0 && shu< 27){panduan = "体重超重";}if (shu>=27  ){panduan = "体重肥胖";}textView.setText("根据"+"中国标准"+String.valueOf(cshengao2.format(cshengao1))+"身高"+String.valueOf(ctizhong2.format(ctizhong1))+"KG体重"+"BMI指数为"+String.valueOf(endjieguo1.format(endjieguo2))+panduan);}}
}

页面展示

Android studio实现计算BMI指数(两个页面之间的跳转)相关推荐

  1. 微信小程序实现两个页面之间的跳转

    两个简单的页面 点击链接实现在两个页面之间的跳转 图片和文字自行设置 步骤 1:创建项目 2:删除多余无用文件和代码 最新版的微信开发者工具不支持创建空白项目,我们需要把原来多余的文件和代码删除 需要 ...

  2. 根据身高体重计算BMI指数,判断您是否健康。

    目录 前言 (1)体质指数 (Body Mass Index,简称BMI) 1.定义 2.计算公式如下: 3.亚裔成年人请用以下的指引: 4.*罹病情况包括 5.该公式可判断人体的健康状况.根据美国有 ...

  3. 题目26:输入体重(单位:Kg)和身高(单位:m),计算BMI指数(BMI指数=体重÷身高的平方),如果BMI <18.5,输出thin;如果18.5≤BMI≤25,则输出normal

    题目转载:http://python.wzms.com/s/1/20 题目描述: 输入体重(单位:Kg)和身高(单位:m),计算BMI指数(BMI指数=体重÷身高的平方),如果BMI <18.5 ...

  4. 计算BMI指数(身体质量指数)

    题目描述 问题:计算BMI指数(身体质量指数).BMI指数(即身体质量指数,简称体质指数又称体重,英文为Body Mass Index,简称BMI),是用体重公斤数除以身高米数平方得出的数字,是目前国 ...

  5. 使用python根据身高体重计算BMI指数

    #python(day01) 根据身高.体重计算BMI指数 创建两个变量:一个用于计算身高(单位:米),一个用来记录体重(单位:千克),根据公式"BMI=体重/(身高*身高)",代 ...

  6. Android Studio导入Eclipse项目的两种方法

    Android Studio导入Eclipse项目有两种方法,一种是直接把Eclipse项目导入Android Studio,另一种是在Eclipse项目里面进行转换,然后再导入Android Stu ...

  7. Java训练01“ 根据身高体重计算BMI指数”

    涉及知识点:1.数据类型的声明和运算 2.控制语句if 题目:创建一个BMIexponent类,声明身高(height)单位是米.声明体重(weight)单位是千克.根据BMI=体重/(身高*身高)  ...

  8. 输入身高、体重计算BMI指数

    //根据身高体重计算BMI指数public static void main(String[] args) {Scanner scanner=new Scanner(System.in);System ...

  9. 练手小程序1.1 if相关练习(计算BMI指数,学生成绩,出租车计费)

    一.计算BMI指数 1. 用户输入身高.体重 2. 计算公式: 体质指数(BMI)= 体重(kg) / 身高^2(m) EX: 70kg / (1.75*1.75) = 22.86 3. 判断标准: ...

最新文章

  1. 原始套接字学习笔记(1)
  2. 【Android 逆向】Android 系统文件分析 ( /system/ 系统命令和系统应用数据目录 | /system/app/ 系统应用目录 | sys Linux 系统内核文件目录 )
  3. python选择题题库for、if_Python题目1:猜年龄(for、if else和where)
  4. Cesium中的相机—YawPitchRoll
  5. Android开发笔记(二十五)assets目录下的文件读取
  6. js typeof 能得到哪几种类型
  7. Vue中如何导入并读取Excel数据
  8. adb 清理内存_教你几招如何清理手机内存,加快运行速度!
  9. MAC 下shell工具推荐 zentermlite
  10. 安徽省计算机二级水平考试试卷,安徽省计算机二级考试理论试题(附答案)
  11. 计算机网络英语求职信范文大全,英文求职信
  12. XPS文件可以直接打印吗?如何转成Word后修改呢
  13. 从零开始学习Openwrt教程
  14. 半小时体验云原生:手把手教你在k8s上部署springboot应用——干货分享,建议收藏
  15. 《啤酒与尿布》之读感
  16. CentOS7.4配置OpenLDAP Client集成AD服务及SSSD服务与SSH服务
  17. 民远学院99届计算机,上海民远职业技术学院计算机基础复习题及参考答案-D套...
  18. 8.17.6. Constructing Ranges
  19. 微信单参数二维码回调配置
  20. 【PHP-网页内容抓取】抓取网页内容的两种常用方法

热门文章

  1. [NOI2008]糖果雨——数形结合的思想
  2. 泛微OA系统E-office11中小企业全能OA办公系统默认的初始密码是什么
  3. 计算机文件管理术语路径描述的是,全国计算机联考一级笔试模拟试题及答案(win7+office2010) (4)...
  4. jsp页面中的判断是否相等(c标签中的if)
  5. 爬虫之js加密参数破解练习-百度指数爬虫(附完整源码)
  6. 轻松上手Snackbar控件
  7. android 自定义 snackbar,自定义Toast以及玩转SnackBar
  8. 一图说明如何修改VisualStudio工程的配置管理器界面宽度
  9. uwsgi模式_uwsgi基础——最佳实践和问题
  10. 2024云南大学计算机考研信息汇总