1

我希望我的 onTextChanged 类在用户输入“空格”时读取,以便我可以清除我的 EditText 视图。问题是按下空格键时没有任何反应。有谁知道我做错了什么?我的程序不会崩溃,它什么也不做。

 public void onTextChanged(CharSequence s, int start, int before,
                    int count) {
                SS.setText(s);
                if (s.equals("r")) {
                    SS.setText(s);
                    et.setText(" ");
                }
            }

                @Override
                public void beforeTextChanged(CharSequence s, int start, int count,
                        int after) {
                    et.setTextColor(Color.parseColor("#000000"));

                }

                @Override
                public void afterTextChanged(final Editable s) {
                    // cancel the previous search if any

                    // toasted();
                    if (delayedAction != null) {
                        handler.removeCallbacks(delayedAction);
                    }
                    // toasted();

                    // define a new search
                    delayedAction = new Runnable() {

                        @Override
                        public void run() {
                            // start your search
                            // toasted();

                            // if (s.toString().equals(current)) {
                            // // toasted(); <== Here is where it needs to work
                            // // Toast.LENGTH_LONG).show();
                            // }

                            et.setTextColor(Color.parseColor("#C0C0C0"));
                            toasted();
                            tv.setText(et.getText().toString());
                            tv.setTextColor(Color.parseColor("#66CC66"));
                            et.setText("");
                        }

                    };
4

2 回答 2

1

它应该s.equals(" ")代替s.equals(' ')

于 2012-08-12T02:29:10.867 回答
0

你可以试试。

Pattern pattern = Pattern.compile("\\s");
Matcher matcher = pattern.matcher(s);
boolean found = matcher.find();
于 2012-08-12T05:27:55.457 回答