我想讓我的onTextChanged類在用戶輸入「空格」時讀取,以便我可以清除EditText視圖。問題是空格鍵被按下時什麼也沒有發生。有人知道我做錯了什麼嗎?我的程序不會崩潰,它什麼都不做。按下按鈕時清除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("");
}
};
試試這個:'et.setText(「」); //沒有空間。我不確定,但我認爲你正在製造一個無限循環。 – iTurki 2012-08-12 02:50:07
「SS」的價值是什麼? – iTurki 2012-08-12 02:56:04
我做了一個新的textview來打印出s的值。並且textview的名字是SS – 2012-08-12 02:58:48