Android screened EditText input

Source: Internet
Author: User

In the recent project to do a selection of the effect of the label, the user can enter the label or directly select the label. The requirement is only one label, it is necessary to allow users to continue to enter after the user has checked the label, but can delete the label. Obviously using setenable (false) is not feasible.

Finally, a method is found that uses the Inputfilter class to filter all fields, displaying an empty string regardless of what the user enters

Etactiontag.setfilters (new  inputfilter[] {                     new  inputfilter () {                          publicintint int int.int  dend)                               {return Src.length () < 1? Dst.subsequence (DStart, DEnd): "";                           }                       

This will ensure that the user is not able to enter. However, there are cases where users cannot delete them at the same time.

So consider the delete key to listen, in the press the DELETE key, while the input box is set to filter the input box directly set to empty. Then the filter of the input box is removed, and then the effect is achieved.

Etactiontag.setonkeylistener (NewOnkeylistener () {@Override Public BooleanOnKey (View V,intKeyCode, KeyEvent event) {                if(Etactiontag.getfilters ()! =NULL){                    if(keycode==Keyevent.keycode_del) {Etactiontag.setfilters (Newinputfilter[]{}); Etactiontag.settext (""); return true; }                }                return false; }                    });

The effect is as follows:

Android screened EditText input

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.