运行文件:

<?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"android:orientation="vertical"><TextViewandroid:layout_width="fill_parent"android:layout_height="70dp"android:layout_marginTop="10dp"android:layout_marginLeft="10dp"android:text="BMI指数计算"android:textColor="@color/black"android:textSize="30sp"android:textStyle="bold"/><TextViewandroid:layout_width="fill_parent"android:layout_height="40dp"android:layout_marginTop="13dp"android:layout_marginLeft="30dp"android:text="身高(cm)"android:textSize="25sp"android:textStyle="bold"android:id="@+id/txt1"/><EditTextandroid:layout_width="fill_parent"android:layout_height="wrap_content"android:id="@+id/edX"/><TextViewandroid:layout_width="fill_parent"android:layout_height="40dp"android:layout_marginTop="13dp"android:layout_marginLeft="30dp"android:text="体重(kg)"android:textSize="25sp"android:textStyle="bold"android:id="@+id/txt2"/><EditTextandroid:layout_width="fill_parent"android:layout_height="wrap_content"android:id="@+id/edY"/><RadioGroupandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal"android:layout_marginTop="20dp"android:id="@+id/rg"><RadioButtonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="男"android:id="@+id/rb1"android:layout_marginRight="30dp"android:checked="true"/><RadioButtonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="女"android:id="@+id/rb2"/></RadioGroup><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:id="@+id/btn"android:layout_marginTop="50dp"android:layout_gravity="center"android:text="计算BMI值"/><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:id="@+id/tvResult"android:textSize="20sp"/></LinearLayout>
package com.example.pro1;import androidx.appcompat.app.AppCompatActivity;import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.TextView;import org.w3c.dom.Text;public class bmi extends Activity implements View.OnClickListener {RadioButton rb1;RadioButton rb2;TextView tvResult;EditText txt1;EditText txt2;Button btn;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.bmi);setViews();}public void setViews() {rb1 = (RadioButton) findViewById(R.id.rb1);rb2 = (RadioButton) findViewById(R.id.rb2);//判断男女tvResult = (TextView) findViewById(R.id.tvResult);txt1 = (EditText)findViewById(R.id.edX);txt2 = (EditText)findViewById(R.id.edY);btn = (Button)findViewById(R.id.btn);btn.setOnClickListener(this);}@Overridepublic void onClick(View v) {double x = Double.parseDouble(txt1.getText().toString());//身高double y = Double.parseDouble(txt2.getText().toString());//体重//体重除以身高的平方double res;String str = "你的BMI指数是:";if(x<=0 || y<=0) {tvResult.setText("值异常,不计算");return ;}x = x/100;res = y / (x*x);String str1 = String.format("%.2f",res);str = str + str1;if(rb1.isChecked())res -= 1;str +=   "      体型:";if(res < 19)str += "过轻";else if(res < 24)str += "适中";else if(res<29)str += "超重";else if(res<34)str += "肥胖";elsestr += "严重肥胖";tvResult.setText(str);}
}

基于Android的BMI指数运算相关推荐

  1. android计算bmi的程序,简单的基于android的BMI计算应用

    写这样的一个程序,纯粹是为了入门,为了练手,为何选择BMI,因为正好手边的书上就是拿这个做例子...何况写个BMI总比写个计算器来的简单...好这就开始了. BMI(即身体质量指数,称简体质指数又称体 ...

  2. 基于python的BMI指数计算器

    # 声明变量 身高.体重 while True: height = input('请输入您的身高(m)') height = float(height) if height <= 0: prin ...

  3. Android开发实用小工具十三——BMI指数计算工具

    文章目录 前言 一.效果展示 二.代码 1.准备工作 2.样式布局 3."BMI指数计算"活动页面 4."BMI计算结果"活动页面 总结 前言 BMI指数计算工 ...

  4. python 一段if语句简单测试bmi指数的代码

    BMI指数(即身体质量指数,简称体质指数又称体重,英文为Body Mass Index,简称BMI),是用体重公斤数除以身高米数平方得出的数字,是目前国际上常用的衡量人体胖瘦程度以及是否健康的一个标准 ...

  5. Android studio实现计算BMI指数(两个页面之间的跳转)

    BMI计算器所实现的内容 1.两个页面的跳转 a.intent组件 2.根据所选单选框中的按钮进行BMI指数的判断 a.单选按钮监听 具体代码呈现 bmicalculate.xml <?xml ...

  6. [任务书+论文+PPT+源码]基于Android与多媒体的英文学习APP的设计与实现

    第1页 毕业设计(论文)题目:基于ANDROID与多媒体技术的英文学习APP的设计与实现设计(论文)要求及原始数据(资料):1.综述国内外移动互联现状及前景:2.了解ANDROID系统,理解ANDRO ...

  7. 基于Android与多媒体的英文学习APP的设计

    毕业设计(论文)任务书 第1页 毕业设计(论文)题目:基于Android与多媒体技术的英文学习APP的设计与实现设计(论文)要求及原始数据(资料):1.综述国内外移动互联现状及前景:2.了解Andro ...

  8. 基于Android平台的流媒体播放器的设计

    from: 基于Android平台的流媒体播放器的设计 1引 言 随着移动通信技术和多媒体技术的迅速发展,融合手机.网络.多媒体技术为一体的视频监控技术也有了长足的进步,通过移动通信网络提供流媒体服务 ...

  9. 光学模拟 Android,基于Android平台的光学字符识别应用的设计与实现

    摘要: 随着数字化时代的蓬勃发展,信息量以指数级的速度增长,然而手工录入并存储信息的速度远不及信息的产生速度.光学字符识别(OCR)技术能够自动化地检测信息并识别出来,有效地解决了信息录入速度和正确率 ...

  10. 安卓bmi项目_Android自定义View实现BMI指数条

    最近项目需要,需要做一个BMI指数的指示条,先上效果图: BMI指数从18到35,然后上面指示条的颜色会随着偏移量的变化而改变,数字显示当前的BMI指数,下面的BMI标准也是根据不同数值的范围来判断的 ...

最新文章

  1. 关于60枚一分两分五分硬币凑成一块钱的解决方法
  2. Octavia Rocky UDP 负载均衡功能试验
  3. Python技巧之“is”对比“==”
  4. helm部署kafka完整记录
  5. 如何定制化SAP Fiori标准应用里UI字段的标签
  6. (转)基于Metronic的Bootstrap开发框架经验总结(5)--Bootstrap文件上传插件File Input的使用...
  7. 电脑如何重装系统之使用PE优盘启动工具安装win10操作系统
  8. ChainX 主网预演暨第三届创世节点大赛正式启动
  9. python下的一个好用的日历库,支持农历和公历互转,是一个很好用的日期包
  10. 洛谷1489 猫狗大战
  11. 关于Met no 'TRANSLATIONS' entry in project错误
  12. Linux添加硬盘并挂载(超细致)
  13. ssh连接Linux机器一直让输入密码
  14. 2021-08-25 新手创建bt面板并创建网站
  15. 【附下载】手摸手带你搭建广告需求平台DSP
  16. 网络营销好学吗?自学和培训该怎么选?
  17. Uncaught (in promise) TypeError: Cannot read property ‘coupon‘ of undefined,页面渲染出来了,但是报上面的错误
  18. 测试apk-异常管控WiFi Scan攻击者开发
  19. python爬取微博热搜
  20. java 某个类 单独输出日志_log4j实现特定功能的日志单独输出到指定的日志文件...

热门文章

  1. 计算机怎么看ping,如何查看自己电脑的PING
  2. xp系统蓝屏代码7b_电脑开机蓝屏错误代码0x0000007B的详细解决过程
  3. mysql表名大小写设置
  4. 拯救win10系统,如何开机进入DOS等删除恶意软件
  5. 读书笔记之《随机漫步的傻瓜》
  6. 如何在手机设置中打开位置定位服务器,手机gps定位功能如何设置
  7. html td 跨两个,【单选题】在HTML中,td标签的( )属性用于创建跨多个行的单元格。...
  8. YOLOv5 NameError: name ‘SPPF‘ is not defined
  9. 鼠标失灵,但鼠标和USB接口都是好的的情况。
  10. 全国各地知名互联网公司内推QQ群