public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
if( editText != null)
{
if(editText.getText().length() > 0){
String TL = null;
DecimalFormat formatter = new DecimalFormat("#,###");
String ss = "";
try{
ss = editText.getText().toString();
ss = ss.replace(".", "");
ss = ss.replace(",", "");
Long number = Long.parseLong(ss);
ss = formatter.format(number);
}catch(Exception e){
ss = e.toString();
}
changeText(editText,ss);
}
editText.setSelection(editText.length());
}
}
当用户输入50000的值时,在editText中应答为50.000。但是,我不想做点。我想用逗号,比如50000。我该怎么做呢?
参见javadoc
formatter.setDecimalSeparator('.');
formatter.setGroupingSeparator(',');
或者更危险的,如global
Locale.setDefaultLocale(Locale.US);