Skip to content

Instantly share code, notes, and snippets.

@enq3
Created March 30, 2017 08:03
Show Gist options
  • Save enq3/19d29251afd43b11193b8d85403f77eb to your computer and use it in GitHub Desktop.
Save enq3/19d29251afd43b11193b8d85403f77eb to your computer and use it in GitHub Desktop.
public class Test {
private Timer timer;
private LoadTimerTask task;
//выполняется после ввода нового символа в поиске
void onSearch(String text) {
//отменяем предыдущую задачу таймера
if (timer != null) {
timer.cancel();
}
timer = new Timer();
task = new LoadTimerTask(text);
//запуститься через 1000мс, если не введен еще символ
timer.schedule(task, 1000);
}
}
class LoadTimerTask extends TimerTask {
private String searchText;
public LoadTimerTask(String text) {
searchText = text;
}
@Override
public void run() {
//поиск searchText
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment