android - Textwatcher - Different Last Char Situations -
android - Textwatcher - Different Last Char Situations -
long story short facing problem: attaching textwatcher edittext. "1" lastly char written on it, should replaced letter "a". here problem: i'd "a" lastly char written on edittext (user pressed "a"), except through previous method, things done. test , type "1", converted "a" , things mention done. can't seem find way overpass this, can suggestions given? lot. use:
public void aftertextchanged(editable s) { //todo auto-generated method stub if (s.length() > 0 && s.tostring().charat(s.length() - 1) == '1') { current_string = s.tostring().substring(0, (s.length() - 1)); et.settext(current_string + "a"); length = s.length(); et.setselection(length); } else if (s.length() > 0 && s.tostring().charat(s.length() - 1) == 'a') { //do things }
do mean.
1)when user enters 1 in end should replace 'a'. 2)when user enters 'a' separately (not converted step 1) should else
amount1.addtextchangedlistener(new textwatcher() { int flagg; public void ontextchanged(charsequence s, int start, int before, int count) { system.out.println("flagg"+s+"#"+flagg ); if (s.length() > 0 && s.tostring().charat(s.length() - 1) == '1' ) { system.out.println("converting , doing nothing"); flagg=1; string current_string = s.tostring().substring(0,(s.length() - 1)); amount1.settext(current_string + "a"); int length = s.length(); amount1.setselection(length); } else if (s.length() > 0 && ( s.tostring().charat(s.length() - 1) == 'a') && flagg == 0 ) { system.out.println("staying same , doing something"); amount2.settext(amount2.gettext().tostring() + "z"); // things } } @override public void beforetextchanged(charsequence s, int start, int count, int after) { if (start != 0) { if ((s.tostring()).substring(s.length() - 1).equals("a")) { flagg = 1; } if ((s.tostring()).substring(s.length() - 1).equals("1")) { flagg = 0; } else { flagg = 0; } } } @override public void aftertextchanged(editable arg0) { } }); //new flagg set in if status
android textwatcher
Comments
Post a Comment