实验题目 实验地点
实验一:描述用户界面 502 实验日期 3-24 机器号 27
一、实验目的 学会写自己的第一个 Android 程序,从最简单的从模拟器上输出“Hello, world!”开始。 二、实验内容 1 , 先
自
己
创
建
一
个
项
目
。
2.此时在窗口右边有一个“Activities”的项目,右击部署到模拟器上 三、实验步骤及结果 1, helloActivity.JAVA package net.lightwinner.app; import android.app.Activity; import android.os.Bundle; package net.lightwinner.app; import android.app.Activity; import android.os.Bundle; package net.lightwinner.app; package net.lightwinner.app;
import android.app.Activity; package net.lightwinner.app; import android.app.Activity; import android.os.Bundle; public class helloActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(yout.main); } } 2.MAIN.JAVA<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> </LinearLayout>
3.STRING<?xml version="1.0" encoding="utf-8"?> <resources> <string name="hello">Hello World, helloActivity!</string> <string name="app_name">我的第一个应用</string> </resources>
四、小结(问题及收获) 让屏幕上显示“Hello,world!,窗口右边有一个“Activities”的项目, ” 打开项目,里面有“res”选项,打开后有“layout>main.xml”,打开如下:,屏幕上输出的“Hello world, main ”可能出自 这里,试着把 world! ”则屏幕上输出了。 中的“@string/hello”改为“Hello,
实验科目 实验题目 实验地点
智能移动终端软件开发 实验二:BMI 应用程序设计 5-502 实验日期 4-12 机器号 27
一、 实验目的 初步掌握 Android 布局开发并运用多个 TextView 界面组件。 二、 实验内容 设计一个允许我们输入身高, 体重并计算 bmi 值的程序, 在屏幕上显示 bmi 的同时,并弹出“你应该节食或多吃”的信息。只要 bmi 超过 25 就算偏胖,低 于 20 就算偏瘦。
三、实验步骤及结果 1.代码 (1)main<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="身高(cm)" /> <EditText android:id="@+id/height" android:layout_width="fill_parent" android:layout_height="wrap_content" android:numeric="integer" android:text="" <TextView android:layout_width="fill_parent" android:layout_
height="wrap_content" android:text="体重(kg)"/> <EditText android:id="@+id/weight" android:layout_width="fill_parent" android:layout_height="wrap_content" android:numeric="integer" android:text=""/> <Button android:id="@+id/submit" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="计算BMI值" /> <TextView android:id="@+id/result" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text=""/> <TextView android:id="@+id/suggest" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="" </LinearLayout> /> /> >
(2)Activity.JAVA package com.demo.android.bmi; import java.text.DecimalFormat; import android.app.Activity;
import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; public class Bmi extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(yout.main); Button button=(Button)findViewById(R.id.submit); button.setOnClickListener(calcBMI); } private OnClickListener calcBMI=new OnClickListener () { public void onClick(View v) { DecimalFormat nf=new DecimalFormat("0.00"); EditText fieldheight=(EditText)findViewById(R.id.height); EditText fieldweight=(EditText)findViewById(R.id.weight); double height=Double.parseDouble(fieldheight.getText().toString())/100; double weight=Double.parseDouble(fieldweight.getText().toString()); double BMI=weight/(height*height); TextView result=(TextView)findViewById(R.id.result); result.setText("Your BMI is "+nf.format(BMI)); TextView fieldsuggest=(TextView)findViewById(R.id.suggest); if(BMI>25) { fieldsuggest.setText(R.string.advice_heavy); } else if(BMI<20) { fieldsuggest.setText(R.string.advice_light); }else { fieldsuggest.setText(R.string.advice_average) } } }; } (3)STRING<?xml version="1.0" encoding="utf-8"?>
搜索“diyifanwen.net”或“第一范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,第一范文网,提供最新IT计算机智能移动终端软件开发实验报告全文阅读和word下载服务。
相关推荐: