Making an EditText object accept only numeric values

筅森魡賤 提交于 2019-12-13 05:36:56

问题


I'd like to create programatically an EditText within this attribute:

android:inputType="number|numberSigned|numberDecimal"

In brief I'd like it to accept only numeric values. How do I have to set my EditText object?


回答1:


The corresponding method for inputType is

public void setInputType (int type)

So something like the below should work (untested)

setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED | InputType.TYPE_NUMBER_FLAG_DECIMAL )


来源:https://stackoverflow.com/questions/7330519/making-an-edittext-object-accept-only-numeric-values

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!