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;
}
@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;
}