Using a SearchView
in my application.
Is there anyway in which I can make the call to onQueryTextChange() method delayed. Like, when user type a sequence o
1) Create abstract class:
public abstract class DelayedOnQueryTextListener implements SearchView.OnQueryTextListener {
private Handler handler = new Handler();
private Runnable runnable;
@Override
public boolean onQueryTextSubmit(String s) {
return false;
}
@Override
public boolean onQueryTextChange(String s) {
handler.removeCallbacks(runnable);
runnable = () -> onDelayerQueryTextChange(s);
handler.postDelayed(runnable, 400);
return true;
}
public abstract void onDelayerQueryTextChange(String query);
}
2) Set it like this:
searchView.setOnQueryTextListener(new DelayedOnQueryTextListener() {
@Override
public void onDelayerQueryTextChange(String query) {
// Handle query
}
});