Xamarin android format string onkey pressed -
i have edittext in want user type credit card number, want format string while user typing it, want string have space every 4 numbers, this:
xxxx xxxx xxxx xxxx
i found use textwatcher , onkeyup couldn't understand how use in edittext, if 1 explain me appreciate it, thanks.
create class implements itextwatcher
interface. add instance of class text changed listener...
public class creditcardformatter : java.lang.object, itextwatcher { private edittext _edittext; public creditcardformatter(edittext edittext) { _edittext = edittext; } public void aftertextchanged(ieditable s) { } public void beforetextchanged(icharsequence s, int start, int count, int after) { } public void ontextchanged(icharsequence s, int start, int before, int count) { } }
in activity.. (or oncreateview
in fragment)
public override void oncreate() { // other code.. myedittext.addtextchangedlistener(new creditcardformatter(myedittext)); }
then use override methods reformat text show need.
Comments
Post a Comment