`

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;
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics