-1

I have a TextWatcher set up and working (nearly) exactly as I want it. However, I would like this TextWatcher to stop as soon as the user enters a '.'. The only solution I have found so far crashes the app if the user entirely deletes the text. It is also important that the ENTIRE TextWatcher ends at the moment the user enters a '.'.

I have tried placing the TextWatcher within the loop, however it doesn't seem to work.

private TextWatcher userEnterListener = new TextWatcher() {

    @Override
    public void afterTextChanged(Editable s) {
        // TODO Auto-generated method stub


    }


    @Override
    public void beforeTextChanged(CharSequence s, int start, int count,
            int after) {



        if(after==0) {
            shownText = "Please try again";
        }
        else if(after==1) {
            shownText = "A";
        }
        else if(after==2) {
            shownText = "An";
        }
        else if(after==3) {
            shownText = "And";
        }
        else if(after==4) {
            shownText = "Andr";
        }
        else if(after==5) {
            shownText = "Andro";
        }
        else if(after==6) {
            shownText = "Androi";
        }
        else if(after==7) {
            shownText = "Android";
        }
        else if(after==8) {
            shownText = "Android A";
        }
        else if(after==9) {
            shownText = "Android Ap";
        }
        else if(after==10) {
            shownText = "Android App";
        }
        else {
            shownText = "Please try again";
        }




    }

    @Override
    public void onTextChanged(CharSequence s, int start, int before,
            int count) {

        recordedString = (s.toString());


        update();


    }




};
Nic Steyn
  • 85
  • 1
  • 6
  • My guess is you're not asking your question correctly. What could you mean by "stop"? Further, your code is... well... not very good. You can replace that silly mess if/else if statements with a single if-statement and a `substring` call. – 323go Aug 10 '13 at 05:41
  • The if/elses were just to make sure I could get the whole thing to work before I worked more on specifics. By stop I mean end the textwatcher that is on the EditText. I want to keep text appearing in the EditText but do not want the TextWatcher doing anything to it. – Nic Steyn Aug 10 '13 at 05:51

1 Answers1

0

maybe this could work:

public void onTextChanged(CharSequence s, int start, int before,
        int count) {

    if(s.toString().equals("Android App") && start == '.'){
        //here add an Empty TextWatcher to the EditText who has this TextWatcher added.
 }
    recordedString = (s.toString());


    update();


}
jac1013
  • 408
  • 3
  • 11