开发者

implement Numerical Edit Text in Android

开发者 https://www.devze.com 2023-04-04 00:26 出处:网络
开发者_如何转开发I am trying to implement getting contents of edit text as a number as exemplified in iOS.
开发者_如何转开发

I am trying to implement getting contents of edit text as a number as exemplified in iOS. The intention is for the user to enter only numerical values.

I am wondering if there is a similar implementation in Android. Can this be done??

I would appreciate some excellent advice. Thanks.


You can use the android:numeric for this like:

<EditText android:text="435.569"
    android:id="@+id/EditText01"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:numeric="integer|decimal" />

to do this dynamically just try something like :EditText.setInputType(InputType.TYPE_CLASS_NUMBER);

Good luck Arkde


The EditText-widget has the inputType-attribute, which can be used to determine what type of input the user should make.

There is also the corresponding method setRawInputType() to set it programmily.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号