allow only number and period(.) in edit text in android

前端 未结 8 960
北海茫月
北海茫月 2020-12-17 09:16

i want to allow only numbers and period(.) in a android edit text. How to do this .. can any body help?

相关标签:
8条回答
  • 2020-12-17 09:56

    You should use the att:

    android:digits="0123456789."

    http://developer.android.com/reference/android/widget/TextView.html#attr_android:digits

    0 讨论(0)
  • 2020-12-17 09:59

    EditText is derived from TextView which has a

    void addTextChangedListener(TextWatcher watcher)
    

    method. TextWatcher has callbacks, like

    abstract void afterTextChanged(Editable s)
    

    that you can implement in order to filter the new text to only contain numbers and period.

    0 讨论(0)
提交回复
热议问题