(安卓计算器小程序.doc
文本预览下载声明
学生实训(验)报告单
课程名称:Google Android开发
指导教师: 冯 曼
班级名称: 11级移动通信1班
学年学期:2012-2013学年第1学
信息科学与工程学院
信息科学与工程学院学生实训(验)报告单
学号: 2011 姓名: 彭法亮
项目名称 计算BMI值的程序 实训目的 掌握Android用户界面开发基础
掌握Button、EditText、TextView组建
3. 掌握MVC设计模式 实训内容 编写计算BMI值的程序,通过输入身高、体重值,计算其BMI值,并给出健康建议。 实训步骤
新建程序BMI:
所需资料:
1.TextView控件能向用户展现文本信息
TextView //现行版面配置
android:layout_width=fill_parent //定义当前视图在屏目上的宽度
android:layout_height=wrap_content //定义当前视图在屏幕上的高度
android:text=身高 (cm)
/
2.EditText控件需要用户输入信息,然后获得内容,交给服务器判断。
EditText android:id=@+id/height
android:layout_width=fill_parent
android:layout_height=wrap_content
android:numeric=“integer
android:text=
/
3.按钮
Button android:id=@+id/submit
android:layout_width=wrap_content
android:layout_height=wrap_content
android:text=計算 BMI
/
4.在string.xml中注册所用信息:
string name=“height”身高(cm)/string
5.新增advice.xml:
advice_light 你该多吃点
advice_average 体型很棒哦
advice_heavy 你该节食了
6.按钮部分:
Button button = (Button)findViewById(R.id.submit);//按钮的监听
button.setOnClickListener(calcBMI); //监听事件的信息
private OnClickListener calcBMI = new OnClickListener() {
public void onClick(View v) {…..}}
7.编辑字段部分:
EditText fieldheight = (EditText)findViewById(R.id.height);
EditText fieldweight = (EditText)findViewById(R.id.weight);
8.运算部分:
double height = Double.parseDouble(fieldheight.getText().toString())/100;
double weight = Double.parseDouble(fieldweight.getText().toString());
double BMI = weight/(height*height);
9.显示结果:
TextView result = (TextView)findViewById(R.id.result);
DecimalFormat nf =new DecimalFormat(0.00);
result.setText(Your BMI is +nf.format(BMI));
10.提示建议部分:
TextView fieldsuggest = (TextView)findViewById(R.id.suggest);
if(BMI25) {
fieldsuggest.setText(R.string.advice_heavy);
}else if(BMI20) {
fieldsuggest.setText(R.string.advice_light);
}else {
fieldsuggest
显示全部