Mobile phone number EditText Input 344 control

Source: Internet
Author: User


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

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.