import android.text.inputfilter;import android.text.spanned;import java.util.regex.matcher; import java.util.regex.pattern;/*** joy on 2015/12/17.** Amount Input Format */public class EditInputFilter implements InputFilter {/*** Maximum number, we take int type maximum value */public static final int MAX_VALUE = 2147483647;/*** number of digits after the decimal point */public static final int PONTINT_LENGTH = 2; Pattern p;public editinputfilter () {p = pattern.compile ("[0-9]*"); // }/*** source the new input string except for the number * start The new input string starts subscript, typically 0* end the new input string end subscript, usually the source length -1* dest before entering the contents of the text box * dstart original content starting coordinates, generally 0* dend original content endpoint coordinates, typically dest length -1*/@Overridepublic charsequence filter (charsequence src,&nBsp;int start, int end,spanned dest, int dstart, int dend) { String oldtext = dest.tostring (); System.out.println (OldText);//Verify the deletion of keys such as if ("". Equals (Src.tostring ())) {return null;} Verify non-numeric or decimal point matcher m = p.matcher (SRC); if (Oldtext.contains (".")) {//If there is already a decimal point, you can only enter the number if (!m.matches ()) {return null;}} else{//You can enter a decimal point and a number if the decimal point is not entered (!m.matches () && !src.equals (".") ) {return null;}} Verify the size of the input amount if (!src.tostring (). Equals ("")) {double dold = double.parsedouble (oldtext+src.tostring ()); if (Dold > max_value) {return dest.subsequence (dstart, dend);} Else if (Dold == max_value) {if (src.tostring (). Equals (".")) {return dest.subsequence (dstart, dend);}}} Verify that the decimal digit precision is correct if (Oldtext.contains (".")) {Int index = oldtext.indexof ("."); int len = dend – index;//decimal place can only be 2-bit if (len > pontint_leNgth) {charsequence newtext = dest.subsequence (dstart, dend); return newText;}} Return dest.subsequence (Dstart, dend) +src.tostring ();}}
Inputfilter[] Filters = {new Editinputfilter ()};
Edit_takeout_money.setfilters (filters);
Amount Input Box