Android实训报告.docx

上传人:b****4 文档编号:12336250 上传时间:2023-04-18 格式:DOCX 页数:22 大小:307.63KB
下载 相关 举报
Android实训报告.docx_第1页
第1页 / 共22页
Android实训报告.docx_第2页
第2页 / 共22页
Android实训报告.docx_第3页
第3页 / 共22页
Android实训报告.docx_第4页
第4页 / 共22页
Android实训报告.docx_第5页
第5页 / 共22页
点击查看更多>>
下载资源
资源描述

Android实训报告.docx

《Android实训报告.docx》由会员分享,可在线阅读,更多相关《Android实训报告.docx(22页珍藏版)》请在冰豆网上搜索。

Android实训报告.docx

Android实训报告

 

Android实训报告

 

 

 

一、实训背景及目的要求

1.1背景简介

Android(读音:

['ændrɔid])是一种以Linux为基础的开放源码操作系统,主要使用于便携设备,目前尚未有统一中文名称,中国大陆地区较多人使用安卓或安致。

Android操作系统最初由AndyRubin创办[5],最初只支持手机.2005年由Google收购注资,并拉拢多家制造商组成开放手机联盟(OpenHandsetAlliance)开发改良,逐渐扩展到到平板电脑及其他领域上[6].2010年末数据显示,仅正式推出两年的操作系统的Android已经超越称霸十年的诺基亚Symbian系统,跃居全球最受欢迎的智慧手机平台。

采用Android系统手机厂商包括HTC、Samsung、Motorola、Lenovo、LG、SonyEricsson等.

1。

2实训目的及要求

Android以Linux为核心的Android行动平台,使用Java作为编程语言。

本实训是在学习java语言程序设计的基础上进行的一次综合实践。

通过综合训练,要求学生掌握java语言程序设计的基本技能和Android编程的应用,并较系统地掌握JAVA语言程序设计开发方法以及帮助文件的使用等,使学生通过本次实训,能够进行独立的Android应用程序开发,能够在实际操作中得到进一步的提高,为以后的学习和工作打下良好的基础。

目的:

1、培养学生运用所学课程Java语言程序设计的理论知识和技能,分析解决计算机实际应用中的问题的能力。

2、培养学生在Java语言程序设计的基础上,开发Android应用程序的思想和方法。

3、培养学生调查研究、查阅技术文献、资料、手册以及编写技术文献的能力。

通过课程设计,要求学生在指导教师的指导下,独立完成课程设计的全部内容,包括:

1、确定开发的程序,收集和调查有关技术资料。

2、按软件工程步骤进行程序设计。

3、对完成的程序进行测试和完善.

4、完成课程设计报告。

二、设计思路

2.1设计题目

以Android系统的UI界面开发为基础,设计一个可以简单计算标准体重的应用程序,要求以2个Acitivity实现,第一个Activity作为输入界面,第二个Activity作为结果输出界面,具体实现细节自行设计。

2。

2功能分析

该设计题目要求实现可计算输出标准体重功能的应用程序。

通过查阅资料可知,按照世界卫生组织推荐的计算标准体重的方法,需要获知的输入信息有性别、身高。

故可在第一屏设置有单选框以确定性别,输入框以获取身高。

另,为了增加程序的实用性,可再设一可选输入框,用来得到实际体重,与标准体重对比,给出用户一些健康提议。

第二屏设置有结果输出显示区域与健康提示显示区域。

2.3模块划分

通过程序功能分析,可将程序划分为2个模块,即2个Activity:

第一个Activity:

两个单选框(RadioButton)获取性别,一个输入框(EditText)获取身高,一个可选输入框(EditText)获取实际体重,一个按钮(Button)及一些提示文本。

第二个Activity:

一个文本显示区(TextViw)显示计算结果,一个可选文本显示区(TextView)显示提示信息。

三、设计实现及代码分析

3。

1第一个Activity

3。

1。

1布局文件:

main.xml:

采用绝对布局,以实现控件精准显示;

RadioGroup包含两个RadioButton,以实现性别男女选择;

两个供输入的EditText限定了输入类型为numberDecimal,以确保只接收数字型数据。

main。

xml完整代码如下:

xmlversion=”1.0"encoding="utf—8"?

>

〈AbsoluteLayoutxmlns:

android=”http:

//schemas.android。

com/apk/res/android"

android:

orientation=”vertical"

android:

layout_width="fill_parent"

android:

layout_height=”fill_parent"

android:

id=”@+id/tv1"

android:

layout_width=”wrap_content"

android:

layout_height="wrap_content"

android:

text="@string/tv1_t"

android:

textSize=”20sp”

android:

layout_x="50px"

android:

layout_y=”25px”

/〉

〈TextView

android:

layout_width="wrap_content”

android:

layout_height=”wrap_content”

android:

text=”@string/tv_sex"

android:

layout_x="50px"

android:

layout_y=”100px"

/〉

〈TextView

android:

layout_width=”wrap_content"

android:

layout_height=”wrap_content"

android:

text="@string/tv_tall”

android:

layout_x="50px”

android:

layout_y=”150px”

/〉

〈RadioGroup

android:

id=”@+id/rg”

android:

layout_width=”wrap_content”

android:

layout_height=”wrap_content”

android:

orientation=”horizontal"

android:

layout_x="95px”

android:

layout_y=”90px"

android:

id="@+id/rb_male"

android:

layout_width="wrap_content”

android:

layout_height=”wrap_content”

android:

text=”@string/male”

/>

android:

id="@+id/rb_female”

android:

layout_width=”wrap_content"

android:

layout_height="wrap_content”

android:

text=”@string/female”

/〉

〈/RadioGroup〉

〈EditText

android:

id="@+id/et_tall"

android:

layout_width=”100px"

android:

layout_height=”40px"

android:

layout_x="100px"

android:

layout_y="140px"

android:

inputType=”numberDecimal”

/>

〈TextView

android:

layout_width="wrap_content"

android:

layout_height=”wrap_content"

android:

layout_x="200px"

android:

layout_y="145px”

android:

textSize=”20sp"

android:

text="cm”

/〉

android:

layout_width=”wrap_content"

android:

layout_height=”wrap_content”

android:

layout_x="50px"

android:

layout_y="200px”

android:

text="@string/tv_real”

/>

android:

id="@+id/et_real"

android:

layout_width="100px"

android:

layout_height=”40px"

android:

layout_x="100px"

android:

layout_y=”230px"

android:

inputType=”numberDecimal”

/〉

android:

layout_width=”wrap_content”

android:

layout_height="wrap_content"

android:

layout_x=”200px”

android:

layout_y="235px"

android:

textSize=”20sp"

android:

text=”kg"

/>

〈Button

android:

id=”@+id/compute"

android:

layout_width=”wrap_content"

android:

layout_height=”wrap_content"

android:

layout_x=”100px"

android:

layout_y="280px”

android:

textSize="20sp"

android:

text=”@string/compute"

/〉

3。

1。

2源代码文件:

MainActivity。

java

使用main。

xml布局文件,为计算按钮(Button)注册事件监听,添加事件响应代码;

实现未填身高提示:

Toast.makeText(MainActivity。

this,R.string。

tall_hint,Toast.LENGTH_SHORT).show();

实现Activity之间跳转设置:

intent.setClass(MainActivity。

this,ResultActivity。

class);

实现Activity之间数据封装传输:

bundle.putDouble("height”,height);

bundle.putString(”sex",sex);

bundle。

putString("real",real);

intent。

putExtras(bundle);

MainActivity.java完整代码如下:

packagecom。

halcyon;

importandroid。

app.Activity;

importandroid.content.Intent;

importandroid。

os。

Bundle;

importandroid。

view。

View;

importandroid.view.View。

OnClickListener;

importandroid.widget.Button;

importandroid。

widget.EditText;

importandroid。

widget。

RadioButton;

importandroid.widget。

Toast;

publicclassMainActivityextendsActivityimplementsOnClickListener{

privateRadioButtonrb1=null;

privateRadioButtonrb2=null;

privateEditTextet=null;

privateEditTextet_real=null;

privateButtonbt=null;

publicvoidonCreate(BundlesavedInstanceState){

super。

onCreate(savedInstanceState);

setContentView(R。

layout.main);

rb1=(RadioButton)findViewById(R.id.rb_male);

rb2=(RadioButton)findViewById(R.id。

rb_female);

rb1。

setChecked(true);//默认为男性选中

et=(EditText)findViewById(R.id。

et_tall);

et_real=(EditText)findViewById(R.id.et_real);

bt=(Button)findViewById(R。

id。

compute);

bt。

setOnClickListener(this);//注册点击事件监听

}

@Override

publicvoidonClick(Viewv){

//TODOAuto—generatedmethodstub

/**事件响应代码,获取性别、身高,判断是否输入了实际体重

*新建Intent对象用于Activity之间跳转,及传输输入的数据

***/

if(et。

getText().toString()。

length()==0){//身高未填提示

Toast。

makeText(MainActivity。

this,R。

string。

tall_hint,Toast。

LENGTH_SHORT)。

show();

}

else{

doubleheight=Double.parseDouble(et。

getText().toString());

Stringreal=et_real.getText().toString();

Stringsex=””;

if(rb1.isChecked()){

sex="M";

}

else{

sex="F";

Intentintent=newIntent();

intent.setClass(MainActivity。

this,ResultActivity。

class);

Bundlebundle=newBundle();//存放数据,以封装传输

bundle.putDouble("height”,height);

bundle。

putString(”sex",sex);

bundle。

putString("real”,real);

intent.putExtras(bundle);

this.startActivity(intent);

}

}

3。

2第二个Activity

3。

2.1布局文件:

result.xml

绝对布局,三个TextView,内容用紫色显示,提示标号用绿色显示,以达到较醒目的感觉。

result.xml完整代码如下:

〈?

xmlversion="1。

0”encoding="utf—8"?

xmlns:

android=”http:

//schemas。

android:

layout_width=”fill_parent”

android:

layout_height=”fill_parent”

android:

layout_margin="10px">

〈TextView

android:

id="@+id/tv_1”

android:

layout_width="wrap_content”

android:

layout_height=”wrap_content"

android:

layout_x="20px”

android:

layout_y="100px"

android:

textSize=”20sp”

android:

textColor=”#8855ff"

/>

android:

id="@+id/tv_2"

android:

layout_width="wrap_content"

android:

layout_height="wrap_content”

android:

layout_x=”20px"

android:

layout_y=”200px”

android:

textSize="20sp”

android:

textColor="#00ff00"

/〉

〈TextView

android:

id=”@+id/tv_3"

android:

layout_width=”wrap_content”

android:

layout_height="wrap_content”

android:

layout_x="20px”

android:

layout_y="240px”

android:

textSize=”20sp"

android:

textColor=”#8855ff”

/>

3。

2.2源代码文件:

ResultActivity.java

使用result.xml布局文件,获取intent,取得传入的数据信息,以

男性:

(身高cm-80)×70﹪=标准体重

女性:

(身高cm-70)×60﹪=标准体重

的标准来计算标准体重,方法

privateStringgetWeight(doubleheight,Stringsex)

实现此功能;

可根据用户是否输入了实际体重,来选择是否显示健康提示信息,方法

privatevoidhealthHint(doubleweight)

实现此功能;

方法privateStringform(doubled)实现数据格式化。

ResultActivity。

java完整代码如下:

packagecom.halcyon;

importjava。

text.NumberFormat;

importandroid.app.Activity;

importandroid。

content。

Intent;

importandroid。

os。

Bundle;

importandroid.widget.TextView;

publicclassResultActivityextendsActivity{

privateTextViewtv_1=null;

privateTextViewtv_2=null;

privateTextViewtv_3=null;

privateIntentintent=null;

privateBundlebundle=null;

privatedoubleheight=0;

privateStringsex=””;

publicvoidonCreate(BundlesavedInstanceState){

super.onCreate(savedInstanceState);

setContentView(R.layout.result);

tv_1=(TextView)findViewById(R。

id.tv_1);

tv_2=(TextView)findViewById(R。

id。

tv_2);

tv_3=(TextView)findViewById(R。

id。

tv_3);

intent=this。

getIntent();

bundle=intent。

getExtras();

height=bundle.getDouble("height”);

sex=bundle.getString(”sex”);

tv_1。

setText(this.getWeight(height,sex));

/**男性:

(身高cm-80)¡Á70﹪=标准体重

*女性:

(身高cm-70)¡Á60﹪=标准体重

***/

privateStringgetWeight(doubleheight,Stringsex){

doubleweight=0;

Stringresult=”";

if(sex。

equals("M”)){

weight=(height-80)*0.7;

result=”这位先生,\n你的标准体重为”+form(weight)+”公斤。

\n";

else{

weight=(height—70)*0。

6;

result="这位女士,\n妳的标准体重为"+form(weight)+”公斤。

\n";

}

healthHint(weight);

returnresult;

privatevoidhealthHint(doubleweight){

/*根据用户是否输入了实际体重来判断是否添加显示提示信息

*如果输入了实际体重,按以下原则给用户以健康提示

*标准体重正负10﹪为正常体重

*标准体重正负10﹪~20﹪为体重过重或过轻

*标准体重正负20﹪以上为肥胖或体重不足

**/

Stringresult=””;

Stringreal=bundle。

getString(”real”);

if(real。

equals("")){

result="";

}

else{

doubler=Double.parseDouble(real);

doublerate=(r-weight)/weight;

if(rate〉0。

2){//过胖

result=this.getString(R.string.very_fat);

elseif(rate>=0。

1&&rate〈=0。

2){//胖

result=this。

getString(R.string.fat);

}

elseif(rate〉-0。

1&&rate〈0。

1){//正常

result=this.getString(R。

string。

normal);

elseif(rate>=-0。

2&&rate<=—0.1){//瘦

result=this.getString(R.string。

thin);

}

elseif(rate<-0。

2){//过瘦

result=this.getString(R。

string.very_thin);

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 成人教育 > 成考

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1