How to force EditText to accept only numbers?

前端 未结 6 1342
借酒劲吻你
借酒劲吻你 2020-12-08 18:32

how to force the EditText to accept only numbers.?

6条回答
  •  生来不讨喜
    2020-12-08 18:52

    Or you can add the following:

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

    this will accept numbers, float point numbers and negative numbers you can remove any of these as needed

提交回复
热议问题