EditText判断用户输入完成,然后进行操作解决方案

private Timer timer = new Timer();
private final long DELAY = 1000; // in ms
EditText editTextStop = (EditText) findViewById(R.id.editTextStopId);
editTextStop.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
@Override
public void onTextChanged(final CharSequence s, int start, int before,
int count) {
if(timer != null)
timer.cancel();
}
@Override
public void afterTextChanged(final Editable s) {
//avoid triggering event when text is too short
if (s.length() >= 1) { timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
// TODO: do what you need here (refresh list)
// you will probably need to use
// runOnUiThread(Runnable action) for some specific
// actions } }, DELAY);
}
}
});
上一篇:Android Studio 环境部署 (转载)


下一篇:用适配器模式处理复杂的UITableView中cell的业务逻辑