EditText mEdit = new EditText(context);
InputType.TYPE_NUMBER_FLAG_DECIMAL、小数点型
InputType.TYPE_CLASS_NUMBER 整数型 设置Input的类型两种都要 mEdit.setInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL|InputType.TYPE_CLASS_NUMBER); 设置字符过滤
mEdit.setFilters(new InputFilter[]{new InputFilter() { @Override public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) { if(source.equals(".") && dest.toString().length() == 0){ return "0."; } if(dest.toString().contains(".")){ int index = dest.toString().indexOf("."); int mlength = dest.toString().substring(index).length(); if(mlength == 3){ return ""; } } return null; }}});
时间: 2024-10-18 20:08:07