Android EditText Mask The expression of third-party IME

Source: Internet
Author: User

The expression of the third-party input method may bring some trouble to the development, generally like the server upload characters are ordinary characters, but testing, is to take out Sogou input method, a few expressions,

Big problem came, either show the exception, or direct crash, but there are very few models, will support, may be the third-party ROM to the Android TextView do some processing, so, we can only kill the bloody expression of the specific method is as follows:

The first is to add Textwatcher to the Edittextview.



When judging the change of the character, the type of the character, whether it is a character, otherwise delete the original character, re-enter;


1Medittextview.addtextchangedlistener (NewTextwatcher () {2 3 @Override4              Public voidaftertextchanged (Editable Editable) {5                 intindex = Contenttext.getselectionstart ()-1;6                 if(Index > 0) {7                     if(Isemojicharacter (Editable.charat (index))) {8Editable edit =Contenttext.gettext ();9Edit.delete (index, index + 1);Ten                     } One                 } A             } -  - @Override the              Public voidBeforetextchanged (Charsequence S,intStartintCountintAfter ) { -  -             } -  + @Override -              Public voidOnTextChanged (Charsequence S,intStartintBefore,intcount) { +  A             } at});

Here is the judge whether the character is an expression;

1     Private Static boolean isemojicharacter (char  codepoint) {2         return ! ( (codepoint = = 0x0) | | (codepoint = = 0x9) | | (codepoint = = 0xA) | | (codepoint = = 0xD) | | ((codepoint >= 0x20) && odepoint <= 0xd7ff)) | | ((codepoint >= 0xe000) && (codepoint <= 0xFFFD)) | | ((codepoint >= 0x10000) && (codepoint <= 0x10ffff)); 3     }





Android EditText Mask The expression of third-party IME

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.