Andriod手机号码3-4-4输入

来源:互联网 发布:fifa17球员数据 编辑:程序博客网 时间:2024/05/24 04:17
/** * @author CatDog *  * @功能描述:格式化输入手机号码3-4-4 */public class PhoneFormatTextWatcher implements TextWatcher {private int oldLength; // 用于对比,否则输入到3或者8位时无法删除private int curLength;public void afterTextChanged(Editable editable) {if (editable != null) {if (curLength > oldLength) {if ((curLength == 4 || curLength == 9)) {editable.insert(oldLength, " ");}} else { // 删除了if (oldLength == 5 || oldLength == 10) {editable.delete(curLength - 1, curLength);}}}}public void onTextChanged(CharSequence s, int start, int before, int count) {curLength = s.length();}public void beforeTextChanged(CharSequence s, int start, int count, int after) {oldLength = s.length();}}

0 0
原创粉丝点击