Hopefully this will help someone. I needed to do this programatically.
Method 1:
editText.setKeyListener(DigitsKeyListener.getInstance(true,true));
Method 2: (method 1 didn't work for me)
First get the default decimal separator based on device locale:
DecimalFormat format = (DecimalFormat) DecimalFormat.getInstance(Locale.getDefault());
DecimalFormatSymbols symbols=format.getDecimalFormatSymbols();
defaultSeperator=Character.toString(symbols.getDecimalSeparator());
Then in your EditText TextWatcher's afterTextChanged add:
editText.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable editable) {
if(editable.toString().contains(defaultSeperator))
editText.setKeyListener(DigitsKeyListener.getInstance("0123456789"));
else
editText.setKeyListener(DigitsKeyListener.getInstance("0123456789" + defaultSeperator));
}
}