安卓手机计算器应用java_安卓体重计算器java源程序 使用Intent在Activity间传输数据...
本帖最后由 dori 于 2020-12-18 23:10 编辑
完成一个体重计算器的应用程序开发。
5.PNG (8.27 KB, 下载次数: 0)
2020-12-15 20:24 上传
6.PNG (3.75 KB, 下载次数: 0)
2020-12-15 20:24 上传
MainActivity文件: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.RadioGroup;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button bn=findViewById(R.id.bn);
final RadioGroup male=findViewById(R.id.male);
//绑定监视器
bn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
EditText et = findViewById(R.id.editText);
Boolean sex = male.getCheckedRadioButtonId()==R.id.rb1?true:false;//true为男,false为女
String height = et.getText().toString();
//创建Intent
Intent intent = new Intent(MainActivity.this, Activity.class);
intent.putExtra("sex", sex);
intent.putExtra("height", height);
startActivity(intent);
}
});
}
}
Activity.java文件:
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;
public class Activity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.result);
TextView tv1 = findViewById(R.id.gender);
TextView tv2 = findViewById(R.id.height);
TextView tv3 = findViewById(R.id.weight);
//获得intent
Intent intent = getIntent();
//获得性别和身高信息
Boolean sex =intent.getBooleanExtra("sex", true);
Integer height = Integer.parseInt(intent.getStringExtra("height"));
if (sex) //男
{
tv1.setText("你是一名男性");
tv2.setText("你的身高是" + height + "厘米");
Double weight = (height - 80) * 0.7;
tv3.setText("你的标准体重是" + weight + "公斤");
} else {
tv1.setText("你是一名女性");
tv2.setText("你的身高是" + height + "厘米");
Double weight = (height - 70) * 0.6;
tv3.setText("你的标准体重是" + weight + "公斤");
}
}
}
activity_main.xml文件:
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=".MainActivity">
android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_constraintTop_toTopOf="parent"
tools:layout_editor_absoluteX="-148dp">
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="40dp" />
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="计算标准体重"
android:textSize="30sp" />
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
android:id="@+id/textView3"
android:layout_width="73dp"
android:layout_height="wrap_content"
android:text="性别:"
android:textSize="20sp" />
android:id="@+id/male"
android:layout_width="337dp"
android:layout_height="match_parent"
android:orientation="horizontal">
android:id="@+id/rb1"
android:layout_width="142dp"
android:layout_height="match_parent"
android:text="男性"
android:textSize="20sp" />
android:id="@+id/rb2"
android:layout_width="147dp"
android:layout_height="wrap_content"
android:text="女性"
android:textSize="20sp" />
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:id="@+id/height"
android:layout_width="73dp"
android:layout_height="wrap_content"
android:text="身高:"
android:textSize="20sp" />
android:id="@+id/editText"
android:layout_width="175dp"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="number"
android:textColor="#E91E63" />
android:id="@+id/textView5"
android:layout_width="72dp"
android:layout_height="wrap_content"
android:text="cm"
android:textSize="20sp" />
android:layout_width="400dp"
android:layout_height="60dp">
android:id="@+id/textView6"
android:layout_width="314dp"
android:layout_height="wrap_content" />
android:id="@+id/bn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="计算"
android:textSize="25sp" />
result.xml文件:
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
android:id="@+id/textView10"
android:layout_width="match_parent"
android:layout_height="158dp" />
android:id="@+id/gender"
android:layout_width="match_parent"
android:layout_height="52dp" />
android:id="@+id/height"
android:layout_width="match_parent"
android:layout_height="52dp" />
android:id="@+id/weight"
android:layout_width="match_parent"
android:layout_height="52dp" />
2020-12-18 23:09 上传
点击文件名下载附件
下载积分: 黑币 -5
安卓手机计算器应用java_安卓体重计算器java源程序 使用Intent在Activity间传输数据...相关推荐
- 华为耳机连接Android手机,华为freebuds2如何连接安卓手机?华为freebuds2连接安卓手机的方法...
华为freebuds2如何连接安卓手机?华为freebuds2耳机采用了最新的V5.0蓝牙版本,只要打开耳机充电盒并按下功能按钮即可在安卓手机上搜索配对,连接方法十分的便捷,接下来的文章中小编竟会带来 ...
- 无游戏Android模拟器,没有安卓手机也可以玩安卓手游,夜神模拟器带你畅玩自走棋...
原标题:没有安卓手机也可以玩安卓手游,夜神模拟器带你畅玩自走棋 自从4月18号自走棋推出测试后,短短的一星期,各种玩法攻略层出不穷,安卓玩家玩的开心,苹果用户看着伤心.只能加紧对制作团队的催促.可是, ...
- android扫描隐藏wifi,安卓手机连接隐藏wifi 安卓连接隐藏wifi密码-192路由网
安卓手机怎么连接隐藏wifi信号?近期有用户向小编咨询这个问题.下面小编用一部华为的荣耀3C手机为例,来给大家演示.介绍安卓手机连接隐藏wifi的操作方法.这里小编要提前说明一下,由于手机运行的安卓版 ...
- 华为耳机android系统通知,华为freelace耳机如何连接安卓手机?华为freelace连接安卓手机的方法...
华为freelace耳机如何连接安卓手机?华为freelace耳机采用了V5.0的蓝牙版本,使用前需要通过蓝牙连接到安卓手机上,接下来的文章中小编将会带来详细的操作方法介绍,需要的朋友不要错过哦! 华 ...
- 安卓手机浏览器排行_安卓手机双11性价比排行发布|拯救者手机发透明版|小米发大光圈手机镜头...
智友新闻2020-11-05 本期摘要: ①安卓手机双11性价比排行榜发布 ②联想拯救者电竞手机 Pro 至尊透明版启动预约 ③小米发伸缩式大光圈镜头概念 安卓手机双11性价比排行榜发布 安兔兔近日发 ...
- 安卓手机主题软件_安卓手机安装不了软件原因和方法
安卓手机不能安装软件其实有很多的原因,排除可以避免的原因(google授权),其他的硬件设施的支持,也可能出现软件不能安装的现象.有的是可以解决的,但有的是强制性原因,那就没有办法了.下面就来分析下软 ...
- 安卓手机浏览器排行_安卓手机性能排行榜:国产手机集体“出位”,华为却在角落哭泣?...
华为手机的芯片一直都坚称是国产的骄傲,但是现在的华为芯片出现了一系列的问题,甚至有人预言在今年九月份之后,华为就不再会获得台积电的芯片供应了.这样,对华为来说无疑是不好的势头,而且芯片刚被市场认可,又 ...
- arduino安卓手机版_剥离安卓!华为鸿蒙系统手机版正式发布:这两大机型率先升级...
国人期待两年的华为鸿蒙系统手机版今天终于正式发布了.其实在鸿蒙手机版发布之前官方已做足预告,不同于安卓和苹果iOS以手机自身为中心进行优化,华为鸿蒙系统手机版在小智看来更像是把手机变成一个互联万物的移 ...
- polycom安卓手机客户端_Spark,安卓上最好用的邮件客户端来了!附App下载
在QQ.微信.钉钉这些即时通信软件的围剿下,才诞生20年不到的电子邮箱俨然已经像上个世纪的产物了.现在还在用Email的大部分是工作需要,私人的话顶多就是收收网站验证码激活邮件之类的.因此大多数人在手 ...
最新文章
- 遥控车_vijos1458_纪中1724_水
- HTML5新元素section和article的区别详解
- docker add-host hostAliases配置/etc/hosts
- hive mysql互导_Hive和MySQL数据互导
- 大话存储系列3——磁盘原理
- 日常笔记(持续更新)
- Visual Studio vs软件下载 vax Visual Assist X VAssistX
- java项目启动就调用方法_Java项目启动时执行指定方法的几种方式
- 如何使用机器学习在一个非常小的数据集上做出预测
- PL/SQL语言简单案例
- 关于在VMware上安装Android x86及FTP详细使用
- 如何查看本机Mac地址
- AT指令和MQTT基础
- 离散信道容量迭代算法
- 做一个网站一般需要多少费用
- win11安装SolidWorks激活时闪退,长时间无响应
- Springboot发送邮件教程
- 计算机科技英语期末课程a,《信息科技英语翻译期末考试 A卷参考答案.doc
- win7计算机连接xp计算机,将win7计算机连接到xp共享打印机的教程
- location 拦截所有_拦截漂浮物浮筒