简体   繁体   中英

clear edittext when button is pressed

I want my onTextChanged class to read when the user enters a "space", so that i can clear my EditText view. The problem is that nothing happens when the space bar is pressed. Does anybody know what im doing wrong? My program does not crash it just does nothing.

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

                    };

应该是s.equals(" ")而不是s.equals(' ')

You can try it.

Pattern pattern = Pattern.compile("\\s");
Matcher matcher = pattern.matcher(s);
boolean found = matcher.find();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM