EditText每输入千隔符的添加

editText.addTextChangedListener(new TextWatcher() {

@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {

}

@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {

}

@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
String edit = editText.getText().toString().trim();
String ed = edit.replace(",", "");
String editNum = customFormat("###,###,###",Double.valueOf(ed));
if(!(edit.equals(editNum))){
editText.setText(editNum);
editText.setSelection(editNum.length());
}
}
});
}
public String customFormat(String pattern, double value ) {
  DecimalFormat myFormatter = new DecimalFormat(pattern);
  String output = myFormatter.format(value);
return output;
}

你可能感兴趣的:(EditText)