Mobile phone number 3-4-4 control
package com.gx_school.util;import com.gx_school.activity.arriveactivity;import android.content.context;import android.text.editable;import android.text.textwatcher;import android.util.log;import android.widget.edittext;public class edittextwatcher{private Context mcontext;public edittextwatcher (context context) {mcontext = context;} /** * limit input Decimal Two bits * @param edittext */public void setpricepoint (final edittext edittext) {edittext.addtextchangedlistener (New textwatcher () {@ Overridepublic void ontextchanged (Charsequence s, int start, int before,int count) {string str = s.tostring (); if (Str.length () > 13) {str = str.substring (0,&NBSP;13); LOG.V ("result", str); Edittext.settext (str); edittext.setselection; return;} if ((Str.length () == 3 | | str.length () == 8) && str.charat (Str.length () - 1) != '-' && before < count) {str += "-"; Edittext.settext (str); Edittext.setselection (str.length ()); return;} Remove Horizontal if (str.length () == 3 | | str.length () == 8) && str.charat (Str.length () - 1) != '- ' && before > count) {str = str.substring (0, str.length () - 1); Edittext.settext (str); Edittext.setselection (Str.length ()); return;}} @Overridepublic void beforetextchanged (Charsequence s, int start, int count , Int after) {log.v ("Result", "beforetextchanged " + s.tostring ());} @Overridepublic void aftertextchanged (editable s) {log.v ("Result", "aftertextchanged " + s.tostring ());});} /** * limit the length of input * @param edittext * @param len */public void seteditlength (final edittext Edittext, final int len) {edittext.addtextchangedlistener (New TextWatcher () {@ Overridepublic void ontextchanged (Charsequence s, int start, int before,int count) {if (s.tostring (). Length () > len) {string str = s.tostring (). Subsequence (0, len). toString (); Edittext.settext (str); Edittext.setselection (Str.length ());}} @Overridepublic void beforetextchanged (Charsequence s, int start, int count , Int after) {} @Overridepublic void aftertextchanged (editable s) {// todo auto-generated method stub}});}}
Reference
Phonenum = (EditText) Findviewbyid (R.id.et_arriver_phonenumber);
New Edittextwatcher (Arriveactivity.this). Setpricepoint (Phonenum);
This article is from the "climb over the mountains to see the Sea" blog, please be sure to keep this source http://670176656.blog.51cto.com/4500575/1704166
Mobile phone number EditText Input 344 control