-1

我有一个 TextWatcher 设置并(几乎)完全按照我的意愿工作。但是,我希望这个 TextWatcher 在用户输入“。”后立即停止。如果用户完全删除文本,我迄今为止发现的唯一解决方案会使应用程序崩溃。同样重要的是,整个 TextWatcher 在用户输入“.”时结束。

我尝试将 TextWatcher 放在循环中,但它似乎不起作用。

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();


    }




};
4

1 回答 1

0

也许这可以工作:

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();


}
于 2013-08-10T05:33:36.287 回答