Open surajshrestha opened 7 years ago
This is what I do:
mSearchView.setOnQueryChangeListener(new FloatingSearchView.OnQueryChangeListener() {
@Override
public void onSearchTextChanged(String oldQuery, String newQuery) {
if(newQuery.length() >= MIN_QUERY_LENGTH){
query = newQuery;
mHandler.removeCallbacksAndMessages(null);
mHandler.postDelayed(mSendQuery, QUERY_DELAY);
}
}
});
Basically I schedule a runnable for QUERY_DELAY ms in the future. If the user keeps typing, the following call to onSearchTextChanged
will override this and schedule a new one. All of this until he finally stops and the last scheduled runnable is allowed to run with the most up to date query.
Do this
var handler = Handler() mSearchView.setOnQueryChangeListener { oldQuery, newQuery -> if (newQuery.length < 3) mSearchView.clearSuggestions() else { handler.removeCallbacksAndMessages(null) handler.postDelayed({ mPresenter.loadSuggestions(newQuery) }, 500) } }
Like in SearchView there is this function onQueryTextSubmit(String query) can called when user submits the query. How to do similar thing using this search library ?