How to add +91 before mobile number in edit text in android? -
i have activity contain edit text in want add +91 before mobile number ,right problem when start entering mobile number 9888888 when enter 9 +91 visible , after 888888.it skip 9 first time...how can resolve issue.
code:-
textwatcher m_mobilewatcher = new textwatcher() { @override public void beforetextchanged(charsequence s, int start, int count, int after) { } @override public void ontextchanged(charsequence s, int start, int before, int count) { } @override public void aftertextchanged(editable s) { if (!s.tostring().contains("+91")) { m_inputmobie.settext("+91"); selection.setselection(m_inputmobie.gettext(), m_inputmobie.gettext().length()); } } }; m_inputmobie = (edittext) m_main.findviewbyid(r.id.input_number); m_inputmobie.addtextchangedlistener(m_mobilewatcher);
you missing line m_inputmobie.settext("+91" + s.tostring());
you have add character typed user edit text text.
textwatcher m_mobilewatcher = new textwatcher() { @override public void beforetextchanged(charsequence s, int start, int count, int after) { } @override public void ontextchanged(charsequence s, int start, int before, int count) { } @override public void aftertextchanged(editable s) { if (!s.tostring().contains("+91")) { m_inputmobie.settext("+91" + s.tostring()); selection.setselection(m_inputmobie.gettext(), m_inputmobie.gettext().length()); } } }; m_inputmobie = (edittext) m_main.findviewbyid(r.id.input_number); m_inputmobie.addtextchangedlistener(m_mobilewatcher);
Comments
Post a Comment