Android开发--身高体重指数(BIM)计算--设计用户界面--指定输入类型(InputType)

/* (程序头部注释开始)
* 程序的版权和版本声明部分
* Copyright (c) 2011, 烟台大学计算机学院学生
* All rights reserved.
* 文件名称:指定输入类型(InputType)

* 作 者: 雷恒鑫
* 完成日期: 2012 年 08 月 5 日
* 版 本 号: V1.0
* 对任务及求解方法的描述部分
* 输入描述:
* 问题描述:Android1.5版之后添加了软件虚拟键盘的功能,该实验通过把“android:numeric替换成 android:inputType”让用户再输入数据时,自动弹出软键盘而且直接弹出的是数字软键盘
* 程序输出:

* 程序头部的注释结束

*/

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/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:inputType="number"
    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>


运行结果:

 

注意:“android:inputType”参数除了替换原有的一些参数之外,还供了更多的参数类型,如果将“android:inputType”的参数设置成“numberDecimal”的话,输入文本框中就可以接受包含小数点的数字,到时候算出来的BMI值就更精确了。

修改后代码如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/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:inputType="numberDecimal"
    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:inputType="numberDecimal"
    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>




 

运行结果:

 

 

经验积累:

1.在Android1.5版之后的新版本中可以直接用“android:inputType”参数来替换“android:password” “android:singleLine” “android:numeric” “android:phoneNumber” “android:capitalize” “android:autoText” “android:editable”这一堆属性。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

leihengxin

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值