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

后端 未结 7 2023
轻奢々
轻奢々 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条回答
  •  抹茶落季
    2021-02-12 13:16

    I found a much cleaner solution,which checks if the string is any type of number including integer, float, long or double.

    import java.math.BigDecimal;
    
    Boolean isNumber;
    
    try {
        BigDecimal n = new BigDecimal(theStingToCheck);
        isNumber = true;
    } catch (Exception e) {
        isNumber = false;
    }
    

提交回复
热议问题