public class CustomEdit extends EditText { public CustomEdit(Context context, AttributeSet attrs) { super(context, attrs); } private String oldText = ""; @Override protected void onDraw(Canvas canvas) { String text = getText().toString(); text = text.replace(",", ""); if (!oldText.equals(text)) { oldText = text; StringBuilder builder = new StringBuilder(); for (int i = 0; i < text.length(); i++) { builder.append(text.charAt(i)).append(","); } setText(builder); setSelection(builder.length()); } super.onDraw(canvas); } }
获取editext中的文本:
String text = getText().toString();
text = text.replace(",","");