SudiptaforAndroid SudiptaforAndroid - 1 month ago 9
Android Question

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

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

Answer

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.