有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

当用户输入“.”时,java Android End TextWatcher

我有一个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();


    }




};

共 (1) 个答案

  1. # 1 楼答案

    也许这可以奏效:

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