Micro-Credit Transfer input box rules (may not be full)
1. Two digits after the decimal point
2, the beginning of the decimal point, showing 0.
3, delete to the first position is the decimal point, the first position is 0, to avoid the occurrence of the decimal point in the first position of the situation
Modify the rules of this friend to come, his rules in order to ensure that two digits after the decimal point has a small bug, has been modified
Http://www.jb51.net/article/99361.htm
Effect:
@Override Public charsequence Filter (charsequence source, int start, int end, spanned dest, int dstart, int dend) {STR
ing sourcetext = source.tostring ();
String Desttext = dest.tostring ();
Verify deletion, such as key if (Textutils.isempty (SourceText)) {if (Dstart==0&&desttext.indexof (pointer) ==1) {//Ensure that the decimal point is not in the first position
return "0";
Return "";
} Matcher Matcher = Mpattern.matcher (source);
If you have entered a decimal point, you can only enter a number if (Desttext.contains (pointer) {if (!matcher.matches ()) {return "";
} else {if (pointer.equals (source)) {//can only enter a decimal points return "";
}//Verify decimal point precision, ensure that only two-bit int index = DESTTEXT.INDEXOF (pointer) can be entered after the decimal point;
int length = Desttext.trim (). Length ()-index;
if (length > Pointer_length&&dstart>index) {return "";
If {//No decimal point is entered, you can enter only the decimal point and number, but first you cannot enter a decimal point and 0 if (!matcher.matches ()) {return "";
else {if (pointer.equals (source) && dstart==0) {//The first position to enter a decimal point return "0."; }}//Verify the size of the input amount double sumtext = double.parsedouble (Desttext + SourcetexT);
if (Sumtext > Max_value) {return dest.subsequence (DStart, dend);
Return Dest.subsequence (DStart, dend) + SourceText; }
EditText style
<edittext
android:id= "@+id/et"
android:layout_width= match_parent "android:layout_height=" Wrap_
Content "
android:textsize=" 20sp "
android:maxlength="
android:inputtype= "Numberdecimal"
>
Set Filter
EditText ed = (edittext) Findviewbyid (r.id.et);
Inputfilter[] is = {new Cashierinputfilter ()};
Ed.setfilters (IS);
Source