收藏 分销(赏)

Android程序设计报告-标准体重.doc

上传人:仙人****88 文档编号:9343863 上传时间:2025-03-22 格式:DOC 页数:12 大小:713.04KB
下载 相关 举报
Android程序设计报告-标准体重.doc_第1页
第1页 / 共12页
Android程序设计报告-标准体重.doc_第2页
第2页 / 共12页
点击查看更多>>
资源描述
Android应用程序设计报告 学院:信息工程与自动化学院 专业:通信工程 班级: 姓名: 学号: 日期:2014年7月8日 一、背景介绍 随着移动通信与Internet向移动终端的普及,网络和用户对移动终端的要求越来越高,而Symbian,Windows Mobile,PalmOS等手机平台过于封闭,不能很好的满足用户的需求,因此市场迫切需要一个开发性很强的平台。经过多年的发展,第三代数字通信(3G)技术活动了广泛的接受,它为移动终端用户带来了更快的数据传输速率。随着3G网络的使用,移动终端不再仅是通讯网络的终端,还将成为互联网的终端。因此,移动终端的应用软件和需要的服务将会有很大的发展空间。Google为此于2007年11月推出了一个专为移动设备设计的软件平台——Android。  Android是一套真正意义上的开发性的移动设备综合平台,它包括操作系统、中间件和一些关键的平台应用。Android是由Linux+Java构成的开源软件,允许所有厂商和个人在其基础上进行开发。Android平台的开放性等特点既能促进技术(包括平台本身)的创新,又有助于降低开发成本,还可以是运营商能非常方便地制定自己的特色化的产品。因此,它具有很大的市场发展潜力。 二、需求分析 如今,伴随着Google Android操作系统的盛行,基于Android SDK的系统开发和基于Android应用的开发等已倍受大家关注。Android应用面向的是普通个体用户,这些用户往往会更加关注用户体验,因此Android应用增加多媒体功能十分必要。就目前的手机发展趋势来看,手机已经不再是单一的通讯工具,更多的手机用户希望在工作、学习之余通过方便灵巧可随身携带的仪器休闲娱乐。 而且近年来,由于人们生活水平的提高,越来越多的人开始关注人体健康,而体重也成为了人们关注的重点,尤其是女性。因此为了迎合众多用户的需求并适应现在的手机的规模,我们提出了一个计算标准体重的设计。 三、设计目的 Android以Linux为核心的Android行动平台,使用Java作为编程语言。本设计是在学习java语言程序设计的基础上进行的一次综合实践。通过综合训练,要求学生掌握java语言程序设计的基本技能和Android编程的应用,并较系统地掌握JAVA语言程序设计开发方法以及帮助文件的使用等,使学生通过本次设计,能够进行独立的Android应用程序开发,能够在实际操作中得到进一步的提高,为以后的学习和工作打下良好的基础。 四、开发环境 操作系统:Windows 7 开发软件:eclipse 开发语言:java+Android类库+xml 五、设计思路 1、功能分析 该设计实现了一个可计算输出标准体重功能的应用程序。通过查询可知,世界卫生组织推荐的计算标准体重的方法为:男性标准体重=(身高- 80)*0.7;女性标准体重=(身高-70)*0.6”。因此需要获知的输入信息有性别、身高。 因此设置两个页面,第一个页面有一个单选框确定性别,一个输入框以获取身高。第二个页面有一个结果输出显示区域。 3、模块划分 通过程序功能分析,可将程序划分为2个模块,即2个Activity: (1)初始化模块:两个单选框(RadioButton)获取性别,一个输入框(EditText)获取身高,一个按钮(Button)及一些提示文本。 (2)结果显示模块:一个文本显示区(TextViw)显示计算结果。 六、程序实现及代码分析 1、第一个Activity(初始化模块) (1)布局文件:main.xml: 采用绝对布局,以实现控件精准显示; ①RadioGroup包含两个RadioButton,以实现性别男女选择,程序如下: <RadioButton android:id="@+id/sex1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="男的" > </RadioButton> <RadioButton android:id="@+id/sex2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="女的" > ②一个供输入的EditText限定了输入类型为numberDecimal,以确保只接收数字型数据。代码如下: </RadioGroup> <EditText android:id="@+id/height" android:layout_width="130px" android:layout_height="wrap_content" android:textSize="18sp" android:layout_x="96px" android:layout_y="142px" android:numeric="decimal" > ③一个“计算”按钮Button,单击可以跳到显示模块界面,显示结果。程序如下: </TextView> <Button android:id="@+id/button1" android:layout_width="70px" android:layout_height="48px" android:layout_x="130px" android:layout_y="232px" android:text="计算"> ④其他显示textview显示包块标题在内的其他文本: <TextView android:id="@+id/title" android:layout_width="243px" android:layout_height="29px" android:text="@string/title" android:textSize="24sp" android:layout_x="36px" android:layout_y="32px" > </TextView> <TextView android:id="@+id/text1" android:layout_width="wrap_content" android:layout_height="37px" android:text="@string/text1" android:textSize="18sp" android:layout_x="40px" android:layout_y="156px" > </TextView> <TextView android:id="@+id/text2" android:layout_width="wrap_content" android:layout_height="29px" android:text="@string/text2" android:textSize="18sp" android:layout_x="40px" android:layout_y="102px" > </TextView> <TextView android:id="@+id/text3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="cm" android:textSize="18sp" android:layout_x="231px" android:layout_y="157px" > (2)源代码文件:EX03_11.java 使用main.xml布局文件,为计算按钮(Button)注册事件监听,添加事件响应代码: public class EX03_11 extends Activity { private EditText et; private RadioButton rb1; private RadioButton rb2; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); /* 载入main.xml Layout */ setContentView(R.layout.main); /* 以findViewById()取得Button对象,并添加onClickListener */ Button b1 = (Button) findViewById(R.id.button1); b1.setOnClickListener(new Button.OnClickListener() { public void onClick(View v) { /*取得输入的身高*/ et = (EditText) findViewById(R.id.height); double height=Double.parseDouble(et.getText().toString()); /*取得选择的性别*/ String sex=""; rb1 = (RadioButton) findViewById(R.id.sex1); rb2 = (RadioButton) findViewById(R.id.sex2); if(rb1.isChecked()) { sex="M"; } else { sex="F"; } /*new一个Intent对象,并指定class*/ Intent intent = new Intent(); intent.setClass(EX03_11.this,EX03_11_1.class); /*new一个Bundle对象,并将要传递的数据传入*/ Bundle bundle = new Bundle(); bundle.putDouble("height",height); bundle.putString("sex",sex); /*将Bundle对象assign给Intent*/ intent.putExtras(bundle); /*调用Activity EX03_11_1*/ startActivityForResult(intent,0); } }); } /* 覆盖 onActivityResult()*/ @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { switch (resultCode) { case RESULT_OK: /* 取得来自Activity2的数据,并显示于画面上 */ Bundle bunde = data.getExtras(); String sex = bunde.getString("sex"); double height = bunde.getDouble("height"); et.setText(""+height); if(sex.equals("M")) { rb1.setChecked(true); } else { rb2.setChecked(true); } break; default: break; } } } 2、第二个Activity(显示模块) (1)布局文件:myalyout.xml 绝对布局,包括一个TextView和一个Button。 ①一个TextView用于显示测试者基本情况及计算标准体重的结果,其初始化代码: <TextView android:id="@+id/text1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="20sp" android:layout_x="50px" android:layout_y="72px" > ②一个Button用于回到上一个模块显示界面,其初始化代码如下: <Button android:id="@+id/button1" android:layout_width="100px" android:layout_height="48px" android:layout_x="110px" android:layout_y="180px" android:text="回上一页"> </Button> (2)源代码文件:EX03_11_1.java ①onCreate函数:使用myalyout.xml布局文件,获取intent,取得传入的数据信息,并将测试人的信息以及计算出的标准体重显示在textview中。实现程序如下: public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); /* 载入mylayout.xml Layout */ setContentView(R.layout.myalyout); /* 取得Intent中的Bundle对象 */ intent=this.getIntent(); bunde = intent.getExtras(); /* 取得Bundle对象中的数据 */ String sex = bunde.getString("sex"); double height = bunde.getDouble("height"); /* 判断性别 */ String sexText=""; if(sex.equals("M")) { sexText="男性"; } else { sexText="女性"; } /* 取得标准体重 */ String weight=this.getWeight(sex, height); /* 设置输出文字 */ TextView tv1=(TextView) findViewById(R.id.text1); tv1.setText("你是一位"+sexText+"\n你的身高是"+height+ "厘米\n你的标准体重是"+weight+"公斤"); /* 以findViewById()取得Button对象,并添加onClickListener */ Button b1 = (Button) findViewById(R.id.button1); b1.setOnClickListener(new Button.OnClickListener() { public void onClick(View v) { /* 返回result回上一个activity */ EX03_11_1.this.setResult(RESULT_OK, intent); /* 结束这个activity */ EX03_11_1.this.finish(); } }); ②标准体重计算函数getWeight: 以男性标准体重=(身高cm-80)×0.7 ;女性标准体重=(身高cm-70)×0.6的标准来计算标准体重。其实现代码如下: private String getWeight(String sex,double height) { String weight=""; if(sex.equals("M")) { weight=format((height-80)*0.7) } else { weight=format((height-70)*0.6); } return weight; } ③由于计算需要计算小数,因此设置了一个四舍五入的method: /* 四舍五入的method */ private String format(double num) { NumberFormat formatter = new DecimalFormat("0.00"); String s=formatter.format(num); return s; } 3、字符串资源文件:strings.xml 在一个Android工程中,我们可能会使用到大量的字符串作为提示信息。这些字符串都可以作为字符串资源声明在配置文件中,从而实现程序的可配置性。 <resources> <string name="app_name">EX03_11</string> <string name="title">计算你/妳的标准体重!</string> <string name="text1">身高:</string> <string name="text2">性別:</string> </resources> 4、程序清单文件:EX03_11Manifest.xml 每一个Android项目都包含一个清单(Manifest)文件,它存储在项目层次中的最底层。清单可以定义应用程序及其组件的结构和元数据。它包含了组成应用程序的每一个组件(活动、服务、内容提供器和广播接收器)的节点,并使用Intent过滤器和权限来确定这些组件之间以及这些组件和其他应用程序是如何交互的。因本程序使用了2个Activity,故对EX03_11Manifest.xml有一定的修改,内容如下: <manifest xmlns:android=" package="irdc.ex03_11" android:versionCode="1" android:versionName="1.0.0"> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".EX03_11" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name="EX03_11_1"></activity> </application> </manifest> 七、程序功能测试及截图 1、工程项目目录 2、程序运行界面: 3、计算结果显示; 八、设计总结 两个周的Android程序设计课程已接近尾声,从开始的什么都不懂,到现在可以看懂并理解一个简单应用程序,还是觉得对于这个课程还是学到很多的。虽然没有通过自己的手亲自设计出一个应用程序,但通过对已有的程序的仔细分析、理解,对于通过eclipse设计并开发一个应用程序还是有了一定的了解。 但是由于没学过JAVA的原因,有些代码的具体意义也不能理解的很透彻,但程序的大概还是能够理解,希望通过这次的课程,可以有一个对于Android应用程序的开始,并通过以后的努力可以通过自己的手亲自写出一个有用的应用程序。
展开阅读全文

开通  VIP会员、SVIP会员  优惠大
下载10份以上建议开通VIP会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传
相似文档                                   自信AI助手自信AI助手

当前位置:首页 > 教育专区 > 小学其他

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2025 宁波自信网络信息技术有限公司  版权所有

客服电话:4009-655-100  投诉/维权电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服