EditText上怎么能只接受整型或浮点值? [英] How can EditText accept only integer or float value?

查看:332
本文介绍了EditText上怎么能只接受整型或浮点值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新的Andr​​oid开发。在我的项目,我使用的EditText,但我想迫使它只能接受一个整数或浮点数。我该怎么办呢?

I am new to Android development. In my project, I’m using EditText, but I want to force it to only accept an integer or float value. How can I do that?

推荐答案

如果你想使用十进制数只在您的EditText

If you want to use Decimal Number only on your EditText

使用XML属性安卓inputType =numberDecimal在你的EditText小部件 您的EditText宣言将是这样的:

use the xml attribute android:inputType="numberDecimal" in your EditText widget your EditText declaration will be like this:

<EditText
    android:id="@+id/editText1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ems="10"
    android:inputType="numberDecimal" />

如果你想使用符号十进制数比将二者结合起来的XML属性安卓inputType =numberDecimal Android的:inputType =numberSigned。您的EditText宣言将是这样的:

If you want to use Signed Decimal Number than combine the two Xml attributes android:inputType="numberDecimal" and android:inputType="numberSigned". Your EditText declaration will be like this:

<EditText
    android:id="@+id/editText1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ems="10"
    android:inputType="numberDecimal|numberSigned" >

</EditText>

这篇关于EditText上怎么能只接受整型或浮点值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆