我怎么能限制输入两个字符的EditText框小数点后? [英] How can I limit the EditText box input to two characters after a decimal place?

查看:111
本文介绍了我怎么能限制输入两个字符的EditText框小数点后?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作有一个EditText盒一个Android应用程序。在此框中我想用户输入的货币。

i'm working on an android application with an EditText box. In this box i want the user to enter currency.

我已经制约了键盘使用数字和小数得心应手的的android:inputType下=numberDecimal的,但我想能够从小数点后进入超过两位数停止用户放置(这样的内容,只是因为我认为这是非常重要的用户清楚他们正在输入的内容保存为一个货币,也可以)。

I have already restricted the keyboard to numbers and decimals using the handy android:inputType="numberDecimal" but i would like to be able to stop the user from entering more than two digits after the decimal place (so that the content is saved as a currency and also just because i think it's important that the user is clear about what they're entering).

不过我没有太多的编程经验,我不知道从哪里开始寻找(验证是pretty很大的话题哈哈)。谷歌搜索了一下,这听起来像我应该让我自己的输入过滤器类的扩展,但我不知道如何去说,或者如果有一个更好的办法。所以任何的建议真的会AP preciated!

However i don't have much programming experience and i don't know where to start looking (validation is a pretty huge topic haha). A bit of googling and it sounds like i should make my own extension of the InputFilter class but i'm not sure how to go about that or if there's a better way. So Any advice would really be appreciated!

推荐答案

使用输入过滤
http://developer.android.com/reference/android/text/InputFilter.html

这篇关于我怎么能限制输入两个字符的EditText框小数点后?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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