How to make part of text in EditText non-removable when using RedMadRobot's input-mask-android? -
i using redmadrobot's input-mask-android library set input mask edittext entering phone numbers.
public class mainactivity extends appcompatactivity { static string input_mask_phone = "{998} [00] [000]-[00]-[00]"; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); edittext login = (edittext) findviewbyid(r.id.login); maskedtextchangedlistener maskedtextchangedlistener = new maskedtextchangedlistener( input_mask_phone, true, login, null, new maskedtextchangedlistener.valuelistener() { @override public void ontextchanged(boolean b, @notnull string s) { } } ); login.addtextchangedlistener(maskedtextchangedlistener); login.setselection(login.length()); } } i setting '998', should not removed when user tries remove. '998' can removed.
<edittext android:id="@+id/login" android:layout_width="match_parent" android:layout_height="wrap_content" android:inputtype="phone" android:text="998"/> how make '998' not removable?
try out sample
private final string mmobileinitial ="+974 "; edittext login = (edittext) findviewbyid(r.id.login); login.settext(mmobileinitial); selection.setselection(login.gettext(), login.gettext().length()); login.addtextchangedlistener(new textwatcher() { @override public void ontextchanged(charsequence s, int start, int before, int count) { } @override public void beforetextchanged(charsequence s, int start, int count, int after) { } @override public void aftertextchanged(editable s) { if(!s.tostring().startswith(mmobileinitial)){ login.settext(mmobileinitial); selection.setselection(login.gettext(), login.gettext().length()); } } });
Comments
Post a Comment