实验二——任务二体重测量计
一:实验现象
二 实验代码
mainactivity
package com.example.weight;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.EditText;
import android.widget.RadioButton;public class MainActivity extends Activity {private Button button1; @Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);Button button1 = (Button) findViewById(R.id.button1);final EditText edittext = (EditText) findViewById(R.id.editText1);button1.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View view) {// TODO Auto-generated method stubString a = edittext.getText().toString();int height =Integer.parseInt(a);double male_weight = (height-80)*0.7;double famale_weight = (height-70)*0.6; Intent intent = new Intent(MainActivity.this, ManActivity.class);RadioButton male = (RadioButton) findViewById(R.id.male);RadioButton famale = (RadioButton) findViewById(R.id.famale);boolean clink1 = male.isChecked();boolean clink2 = famale.isChecked();if(clink1){intent.putExtra("sex","你是一名"+male.getText()+"性\n");intent.putExtra("height", "你的身高是" + a + "厘米\n"); intent.putExtra("weight", "你的标准体重是"+male_weight+"公斤");}if(clink2){intent.putExtra("sex","你是一名"+famale.getText()+"性\n");intent.putExtra("height", "你的身高是" + a + "厘米\n"); intent.putExtra("weight", "你的标准体重是"+famale_weight+"公斤");} startActivity(intent); }});}@Overridepublic 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;}}
manactivity
package com.example.weight;import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.TextView;public class ManActivity extends MainActivity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_man);TextView textview =(TextView) this.findViewById(R.id.manacticity);Intent intent =getIntent();String sex =intent.getStringExtra("sex");String height =intent.getStringExtra("height");String weight =intent.getStringExtra("weight");textview.setText(sex+height+weight);}@Overridepublic boolean onCreateOptionsMenu(Menu menu) {// Inflate the menu; this adds items to the action bar if it is present.getMenuInflater().inflate(R.menu.man, menu);return true;}}
activity_main (layout)
<span style="font-size:14px;"><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"android:paddingBottom="@dimen/activity_vertical_margin"android:paddingLeft="@dimen/activity_horizontal_margin"android:paddingRight="@dimen/activity_horizontal_margin"android:paddingTop="@dimen/activity_vertical_margin"tools:context=".MainActivity" ><TextViewandroid:id="@+id/txt"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentTop="true"android:layout_centerHorizontal="true"android:layout_marginTop="27dp"android:text="计算你的标准体重"android:textAppearance="?android:attr/textAppearanceLarge" /><RadioGroupandroid:id="@+id/rg1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignTop="@+id/sex"android:layout_toRightOf="@+id/sex"android:orientation="horizontal" ><RadioButtonandroid:id="@+id/male"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="男性" /><RadioButtonandroid:id="@+id/famale"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginRight="@+id/male"android:text="女性" /></RadioGroup><TextViewandroid:id="@+id/sex"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignLeft="@+id/txt"android:layout_below="@+id/txt"android:layout_marginTop="25dp"android:text="性别"android:textAppearance="?android:attr/textAppearanceLarge" /><TextViewandroid:id="@+id/height"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentLeft="true"android:layout_below="@+id/radioGroup1"android:layout_marginLeft="30dp"android:layout_marginTop="18dp"android:text="身高"android:textAppearance="?android:attr/textAppearanceLarge" /><EditTextandroid:id="@+id/number"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignBaseline="@+id/height"android:layout_alignBottom="@+id/height"android:layout_toRightOf="@+id/height"android:ems="10"android:inputType="number" /><Buttonandroid:id="@+id/button1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_centerVertical="true"android:layout_toRightOf="@+id/sex"android:text="计算" /></RelativeLayout></span>
activity_man (layout)
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"android:paddingBottom="@dimen/activity_vertical_margin"android:paddingLeft="@dimen/activity_horizontal_margin"android:paddingRight="@dimen/activity_horizontal_margin"android:paddingTop="@dimen/activity_vertical_margin"tools:context=".ManActivity" ><TextViewandroid:id="@+id/manacticity"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentTop="true"android:layout_centerHorizontal="true"android:layout_marginTop="25dp"/></RelativeLayout>
三 实验体会
在mainactivity中定义button 和 edittext ,然后定义一个变量,传入身高,利用函数进行计算得出标准体重。在layout中radiobutton,要让用户在男性和女性中只能选择一个,就要用到radiogroup,把两个radiobutton放入radiogroup中。在activity中要选择性别,然后进行运算。点击性别,if语句来选择,用intent来传送数据,在manactivity中表示。
在manactivity中getintent,定义字符串接收传送的数据,最后用textview.setText来显示
实验二——任务二体重测量计相关推荐
- android实验二之体重标准计算器
实验效果图: 计算结果图: MainActivity.java ShowActivity.java activity_main.xml
- 20172319 实验二《树》实验报告
20172319 2018.11.04-11.12 实验二<树> 实验报告 课程名称:<程序设计与数据结构> 学生班级:1723班 学生姓名:唐才铭 学生学号:20172319 ...
- #20155235 《网络攻防》 实验二 后门原理与实践
20155235 <网络攻防> 实验二 后门原理与实践 实验目的 建立一个后门连接是如此的简单,功能又如此强大.通过亲手实践并了解这一事实,从而提高自己的安全意识 . 实验内容 (1)使用 ...
- 网络对抗技术_实验二_网络嗅探与欺骗
中国人民公安大学 Chinese people' public security university 网络对抗技术 实验报告 实验二 网络嗅探与欺骗 学生姓名 岳庆伟 年级 2014级 ...
- 实验二 网络嗅探与欺骗
实验二 中国人民公安大学 Chinese people' public security university 网络对抗技术 实验报告 实验二 网络嗅探与欺骗 学生姓名 刘安然 学号 20 ...
- 20145207《Java程序设计》实验二(Java面向对象程序设计)实验报告
<Java程序设计>实验二(Java面向对象程序设计)实验报告 目录 改变 Java面向对象程序设计实验要求 实验成果 课后思考 改变 看了下之前实验二的整体,很搞笑,大图+代码,没了.. ...
- 2017-2018-2 1723《程序设计与数据结构》第八周作业 实验二 第一周结对编程 总结...
作业地址 第八周作业:https://edu.cnblogs.com/campus/besti/CS-IMIS-1723/homework/1847 (作业界面已评分,可随时查看,如果对自己的评分有意 ...
- 网络对抗技术实验二,第一部分,第二部分
中国人民公安大学 Chinese people' public security university 网络对抗技术 实验报告 实验二 网络嗅探与欺骗 学生姓名 宋得立 年级 2014 区 ...
- 2017-2018-1 20155213 20155303 实验二 固件程序设计
2017-2018-1 20155213 20155303 实验二 固件程序设计 任务一:固件程序设计-1-MDK 注意不经老师允许不准烧写自己修改的代码 两人(个别三人)一组 参考云班课资源中&qu ...
最新文章
- 用PHP计算个税,PHP计算个人所得税示例【不使用速算扣除数】
- html使用highcharts绘制饼图,html js highcharts绘制圆饼图表
- 更改Ubuntu gcc、g++默认编译器版本
- 初学者python编辑器-分享|Mu 入门:一个面向初学者的 Python 编辑器
- 第 21 章 radiusd - Authentication, Authorization and Accounting server
- 非对称加密算法RSA--转
- ubuntu php多版本共存切换
- Java并发编程实战 第13章 显式锁
- java避免使用orderby_java – @OrderBy在JPA中无法正常工作
- 冈萨雷斯《数字图像处理》读书笔记(九)——形态学图像处理
- 一个大数据应用是如何炼成的?
- 使用 Gogs 搭建自己的 Git 服务器
- nodejs之http-proxy几点常见问题 1
- linux ubi 分区,Linux ubi子系统原理分析
- 为什么要进行软件验收测试?如何获得软件验收测试报告
- 最简单DIY基于STM32单片机的蓝牙智能小车设计方案
- cocoscreator的Bundle加载问题
- JVM学习 -- JVM 性能调优监控工具 jps、jstack、jmap、jhat、jstat、hprof 使用详解
- 硬件设计之JTAG转USB转换芯片
- Kotlin-简约之美-进阶篇(十):扩展函数和扩展属性
热门文章
- 数据指标体系设计——以内容产品为例
- 美股市场ETF的中文名列表
- Zabbix的API接口
- python怎么安装开发版_【干货】开发板上安装python的hiai库和opencv库
- 精读《论语》读后感作文3600字
- 微信小程序引用腾讯视频
- Spring Cloud 分布式消息—Spring Cloud Stream 自定义通道与分组分区应用
- 计算机光盘放不了是怎么回事,光盘放入光驱没有反应怎么回事?如何解决?
- mysql8.0错误1406_mysql – SQL错误1406列的数据太长
- 电脑开机时出现DHCP...