Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - Limit only one decimal point enter into a EditText

I need help to only allow one decimal point to be entered into a EditText view. An example: I don't want 123.45.2 or 123..452 to be allowed. Once one decimal point is entered, no more are allowed.

like image 571
KevinM Avatar asked May 21 '11 19:05

KevinM


1 Answers

Play around with this however you like it.

myEditText.setKeyListener(DigitsKeyListener.getInstance(true,true));

Returns a DigitsKeyListener that accepts the digits 0 through 9, plus the minus sign (only at the beginning) and/or decimal point (only one per field) if specified.

like image 98
rochdev Avatar answered Sep 28 '22 12:09

rochdev