How to determine if an input in EditText is an integer?

后端 未结 7 2039
轻奢々
轻奢々 2021-02-12 12:48

Hi I\'m a newbie in Android Programming.

I\'m trying to build an activity which includes an edittext field and a button. When user type in an

7条回答
  •  旧时难觅i
    2021-02-12 13:35

    Since API level 1, Android provides an helper method to do just that (no need to use regex or catching exception) : TextUtils.isDigitsOnly(CharSequence str)

    boolean digitsOnly = TextUtils.isDigitsOnly(editText.getText());
    

    Note that this method returns true with empty String : Issue 24965

提交回复
热议问题