Android High imitation micro-credit transfer money input box rules _android

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.