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