[英]clear edittext when button is pressed
我希望在用户输入“空格”时读取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("");
}
};
应该是s.equals(" ")
而不是s.equals(' ')
你可以试试。
Pattern pattern = Pattern.compile("\\s");
Matcher matcher = pattern.matcher(s);
boolean found = matcher.find();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.