-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 に答える